本文介绍了Java帮助如何读取文件linebyline的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

currentTimeMillis();





while(linReader.hasNext())

{

String line = linReader.nextLine();

System.out.println(line);

}

linReader .close();

long estimatedTime = System.currentTimeMillis() - start_time;

System.out.println(估计时间);

}

}

}

>



我有什么试过:



<

currentTimeMillis();


while (linReader.hasNext())
{
String line = linReader.nextLine();
System.out.println(line);
}
linReader.close();
long estimatedTime = System.currentTimeMillis() - start_time;
System.out.println(estimatedTime);
}
}
}
>

What I have tried:

<

 else{
			 Scanner linReader = new Scanner(inputfile);
			        long start_time = System.currentTimeMillis();


			        while (linReader.hasNext())
			        {
			            String line = linReader.nextLine();
			            System.out.println(line);
			            }
			        linReader.close();
                        long estimatedTime = System.currentTimeMillis() - start_time;
			            System.out.println(estimatedTime);
            }
}
}







我想尝试通过linebyline方法读取文件,我希望时间作为输出。但我的逐行方法不是输出时间。而不是给它时间,它给我这个作为输出



输入输入文件namek.txt

输入输出文件namei.txt

按0和1进入模式

0 - 逐个字符模式

1 - 表示逐行模式

1

k.txt

0



哪个错了




I am trying to read file through linebyline method and i want time as output. But my line by line method is not outputting time. Instead of giving time, it is giving me this as output

Enter an input file namek.txt
Enter an output file namei.txt
Enter an mode by pressing 0 and 1
0 -- character-by-character mode
1 -- means line-by-line mode
1
k.txt
0

Which is wrong

推荐答案

FileInputStream fstream;
BufferedReader br;
fstream = new FileInputStream(fileName);
br = new BufferedReader(new InputStreamReader(fstream, "UTF-8"));
String line;
while ((line = br.readLine()) != null) {
    System.out.printlne(line);
}
br.close();


Scanner linReader = new Scanner(inputStream);



您需要更多地使用Java文档: []。


这篇关于Java帮助如何读取文件linebyline的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 04:10