Reading files with Java

Posted by sikas on Stack Overflow See other posts from Stack Overflow or by sikas
Published on 2010-05-28T11:21:23Z Indexed on 2010/05/28 11:32 UTC
Read the original article Hit count: 164

Filed under:
|

I would like to know how can I read a file byte by byte then perform some operation every n bytes.

for example:

Say I have a file of size = 50 bytes, I want to divide it into blocks each of n bytes. Then each block is sent to a function for some operations to be done on those bytes. The blocks are to be created during the read process and sent to the function when the block reaches n bytes so that I don`t use much memory for storing all blocks.

I want the output of the function to be written/appended on a new file.

This is what I've reached to read, yet I don't know it it is right:

fc = new JFileChooser();
File f = fc.getSelectedFile();
FileInputStream in = new FileInputStream(f);
byte[] b = new byte[16];
in.read(b);

I haven't done anything yet for the write process.

© Stack Overflow or respective owner

Related posts about java

Related posts about java.io