0

Im trying to print an entire .txt file. 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? From the examples Im finding on stack Im just getting confused. This is my code. How do I implement a while loop to print "file1"?

Thanks

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

file1 = inFS.next();

System.out.println( file1 );
Mikitori
  • 589
  • 9
  • 21
ANC2017
  • 1
  • 1
  • 7

1 Answers1

0
 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

Community
  • 1
  • 1
interesting-name-here
  • 1,851
  • 1
  • 20
  • 33