Q:

BufferedReader offset into file contents

I want to get the characters of a file and I know that the first 128 bytes are garbage and the next 4 give me important details.
Currently I am doing this:
    br = new BufferedReader(new FileReader(path));
    char[] cbuf = new char[133]; 
    br.read(cbuf, 0, 132);
    String importantDetails = "";
    for(int i=128;i<132;i++) importantDetails += cbuf[i];

But I feel that it is a really ugly way to do it, first I tried:
    String importantDetails = cbuf.toString().substring(128); 

Which gives an error (String index out of range: -118).
While just the cbuf.toString() prints [C@d70c109.
Is there a better way to accomplish this in java?
I feel that there should be a offset in the file (because the offset of the read(cbuf[],offset,length) is the offset in the cbuf[] and not in the file to be read.

A:

You can use RandomAccessFile to do exactly that. The code :
  RandomAccessFile file = new RandomAccessFile(path, "r");
  file.seek(128); // Sets the file-pointer offset
  byte[] b = new byte[4];
  file.readFully(b);

should do what you want (minus all error checking).
See the javadoc for more details :

