如何使用Java文件中的特定行号读取特定行?

问题描述:

在 Java 中,是否有任何方法可以从文件中读取特定行?例如,读取第 32 行或任何其他行号.

In Java, is there any method to read a particular line from a file? For example, read line 32 or any other line number.

除非您事先了解文件中的行,否则无法直接访问第 32 行而不阅读前 31 行.

Unless you have previous knowledge about the lines in the file, there's no way to directly access the 32nd line without reading the 31 previous lines.

这适用于所有语言和所有现代文件系统.

That's true for all languages and all modern file systems.

如此有效,您只需阅读行,直到找到第 32 行.

So effectively you'll simply read lines until you've found the 32nd one.