Can we get a field in a binary file without reading the whole line..? For example, I have a binary file, and one "line" or record have 10 integers on it..
In my code I use this:
This probably is not a good implementation of reading lines/records from a binary file. Because I only want the data in line[2] to be processed but I am still reading the other data... Is there a way to get the line[2] (data in index 2) directly without reading the whole binary file line/record?
I think these methods from the api are the answer but I'm not sure (and I don't want to create more arrays hopefully):
int read(byte[] b)
Reads some number of bytes from the contained input stream and stores them into the buffer array b.
int read(byte[] b, int off, int len)
Reads up to len bytes of data from the contained input stream into an array of bytes.
Hope you can shed me some light here. Thanks!!!
SCJP/OCPJP 6 | SCWCD/OCPJWCD 5 | OCPJBCD in progress
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 32768
posted
0
No, those methods don't allow you to skip over data.
If you can calculate exactly the byte location within the file, then you can use the RandomAccessFile class.