0

Im trying to read a text file, x bytes at a time into a variable, process each "chunk" and write it to another file.

So far all I can do sucessfully is:

// read each line at a time:
while ( ( str = in.readLine() ) != null){ ....

Is it possible to specify something like... str = in.readBytes( 320 up to 400 ) ... ???

Any thoughts or comments welcome.

1 Answer 1

4

What you're looking for is read(byte[]).

So you would something like:

InputStream in; // initialized however you're doing
int bytesRead = 0;
byte bytes[60]; // We'll read in up to 60 bytes at a time
while ((bytesRead = in.read(bytes)) > 0) {
    // bytesRead is = to the number of bytes actually read
    // bytes array holds the next 'bytesRead' number of bytes
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.