0

Is there a way to read from a file via readline() and an offset in java? For example, file.readline(10) return the 10's line of the file without reading the first 9.

user2422196
  • 297
  • 3
  • 13

2 Answers2

1

readline doesn't provide such functionality. You can use seek function to set an offset (link to related question. However, it has no way of knowing about newline symbols or anything else. It simply sets offset in bytes. If length of your lines is fixed - you can use it just like you want. Otherwise - you need to use readline several times to get required string.

Community
  • 1
  • 1
marvelousNinja
  • 1,510
  • 9
  • 15
0

I don't think so, how would it know that this line is the 10'th line if it hadn't read the first 9 ?. But you can read the file once,store it in an ArrayList or some Data Structure and than access each line alone. You can store line 1 in index ,line 2 in index 2...

Roudy Tarabay
  • 449
  • 1
  • 4
  • 18
  • the problem is that i don't want to read the whole file because it is very big. i think the best solution for my problem is editing the file, so that every line has the same size. then i can set the line with the read bytes method. – user2422196 Feb 01 '14 at 13:00