简体   繁体   English

使用while循环打印.txt文件

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

Im trying to print an entire .txt file. 我正在尝试打印整个.txt文件。 I can only get the first line of the file to print. 我只能获取要打印文件的第一行。 I think I need a while loop to get the entire file to print? 我想需要一个while循环才能打印整个文件? From the examples Im finding on stack Im just getting confused. 从示例中,我在堆栈上发现的Im感到困惑。 This is my code. 这是我的代码。 How do I implement a while loop to print "file1"? 如何实现while循环以打印“ file1”?

Thanks 谢谢

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);
 }

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

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

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