我试图打印整个.txt文件。我只能打印要打印的文件的第一行。我想我需要一个while循环来打印整个文件?从示例中我发现堆栈我只是感到困惑。这是我的代码。如何实现while循环打印" file1"?
由于
fileByteStream = new FileInputStream("Folder/mytext.txt");
inFS = new Scanner(fileByteStream);
file1 = inFS.next();
System.out.println( file1 );
答案 0 :(得分:0)
BufferedReader br = new BufferedReader(new FileReader("Folder\mytext.txt"));
String line = null;
while ((line = br.readLine()) != null) {
System.out.println(line);
}