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

查看:236
本文介绍了如何使用Java中的文件中的特定行号读取特定的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中,是否有任何方法从文件中读取特定的行?例如,读取第32行或任何其他行号。 解除方案

除非你有关于文件中的行的知识,否则没有办法直接访问第32行,没有阅读前面的31行。

所有语言和所有现代文件系统都是如此。



所以你只需要简单地阅读直到找到第三十二行即可。


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

解决方案

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.

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

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

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