如何使用Java文件中的特定行号读取特定行? [英] How to read a specific line using the specific line number from a file in Java?

查看:35
本文介绍了如何使用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.

这篇关于如何使用Java文件中的特定行号读取特定行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆