如何从java中的文件中读取单行 [英] How to read a single line from file in java
本文介绍了如何从java中的文件中读取单行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从java中的文本文件中读取单行。
以及知道该行已完成的标准是什么。
How can i read single line from a text file in java. and what is the criteria of knowing that line is completed.
其次
我读取文件然后对于Read Line函数并将其转换为字符串将跳过大量数据?应该是什么问题?
这是我的代码
i read file and then for Read Line function and converting it into string will skip a lot of data? what should be the problem? Here is my code
String data = new String();
while(infile.readLine() != null) {
data = infile.readLine();
System.out.println(data);
}
推荐答案
更改代码如下
while((data = infile.readLine()) != null) { // read and store only line
System.out.println(data);
}
在当前代码中
while(infile.readLine() != null) { // here you are reading one and only line
data = infile.readLine(); // there is no more line to read
System.out.println(data);
}
这篇关于如何从java中的文件中读取单行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文