O'Reilly logo

Java™ Phrasebook by Timothy Fisher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Reading Binary Data

InputStream is = new FileInputStream(fileName);
											int offset = 0;
											int bytesRead =
											is.read(bytes, offset, bytes.length-offset);

Using the read() method, we can read binary data from a file into an array of bytes. In this phrase, we read from the is input stream into the bytes byte array. In this phrase, the bytes array is assumed to have been previously initialized as a byte array, and the fileName variable is the name of a valid file. The offset variable points to a starting location in the bytes array to begin writing the data to. This is useful when you are in a loop reading data from a file and you don’t want to overwrite previous data stored in the byte array. For each iteration through the loop, you would update the offset ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required