while (inputStream.hasNextLine()){
System.out.println(count);
count = count + 1 ;
}
例如我的文本文件有 1,000 行,每行都有信息。它似乎正在计算所有数字,而不是每一行。
最佳答案
假设inputStream
是一个Scanner
,您需要使用来自InputStream
的数据
while (inputStream.hasNextLine()) {
inputStream.nextLine(); <-- add this
...
关于java - 计算txt文件java文件io中的行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28702541/