Search code examples
javafile-ioiorandom-accessreadblock

Reading records from file of Pagesize only


I am a beginner and I have a file having variable sized records; there are two fields per row i.e. one is 7-15 digits key and then followed by space there is a string which is also variable sized for each record.

I am trying to read bytes only of page size into my buffer and then process them.

The problem is that if i use Java.RanomAccessFile and use seek method to reach a particular line , then i use ReadFully method to read those 1024 bytes into my buffer. I have written the functions to convert byte into int and byte into string -but the problem is that I dont know how many bytes form that 7-15 digit and how many bytes form my string.


Solution

  • When you say a row, do you mean each row has a line separator in between? If that is the case, you can use something like BufferedReader's readline() method. That gives you a string which is 1 line without the line separator.