Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start reading a file at specific position?

First of all I have a couple hours experience with Java so, If its a bit simple question, sorry about that.

Now, I want to read a file but I dont want to start at the beginning of file instead I want to skip first 1024 bytes and than start reading. Is there a way to do that ? I realized that RandomAccessFile might be useful but I'm not sure.

try {
     FileInputStream inputStream=new FileInputStream(fName);
       // skip 1024 bytes somehow and start reading .
} catch (FileNotFoundException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
}
like image 468
TheGost Avatar asked Oct 16 '25 02:10

TheGost


1 Answers

You will want to use the FileInputStream.skip method to seek to the point you want and then begin reading from that point. There is more information in the javadocs about FileInputStream that you might find interesting.

like image 71
dcolish Avatar answered Oct 17 '25 16:10

dcolish



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!