Read data from the file and return the same data in a string It only returns the last line, how can I return the same data in the file?
File
This is test file.
This is test file!
Test
test file
xxas test
fil
! test
te
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Read {
static String input = "";
public static void main (String [] args) throws FileNotFoundException {
Scanner file = new Scanner(new File("Example.txt"));
while(file.hasNextLine()){
input = file.nextLine();
}
System.out.println(input);
}
}