繁体   English   中英

使用while循环打印.txt文件

[英]Printing a .txt file with a while loop

我正在尝试打印整个.txt文件。 我只能获取要打印文件的第一行。 我想需要一个while循环才能打印整个文件? 从示例中,我在堆栈上发现的Im感到困惑。 这是我的代码。 如何实现while循环以打印“ file1”?

谢谢

fileByteStream = new FileInputStream("Folder/mytext.txt");
inFS = new Scanner(fileByteStream);

file1 = inFS.next();

System.out.println( file1 );
 BufferedReader br = new BufferedReader(new FileReader("Folder\mytext.txt"));

 String line = null;

 while ((line = br.readLine()) != null) {
   System.out.println(line);
 }

重复https://stackoverflow.com/a/15696024/5224021

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM