My code is follows:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Movies {
public String rFile() {
try {
Scanner file = new Scanner(new File("./file.txt"));
while(file.hasNextLine()) {
System.out.println(file.nextLine());
}
} catch (FileNotFoundException e) {
System.out.println("File not found!");
}
return "";
}
public static void main(String[] args) {
Movies movies = new Movies();
movies.rFile();
}
}
My file.txt file is as below: 1994 The Shawshank Redemption 1972 The Godfather 1974 The Godfather: Part II
The output is as below: 1994 The Shawshank Redemption 1972 The Godfather 1974 The Godfather: Part II
I don't know why it is printing those characters at the begining.