Pergunta

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.

Foi útil?

Solução

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.

Outras dicas

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...

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top