This is part of my list (it is contained in a .txt file):
Gladiator (The Gladiator) (2000) 8.5
Rate
The Dark Knight
The Dark Knight (2008) 9
Rate
Slumdog Millionaire
Slumdog Millionaire (2008) 8
Rate
Infiltrators
Infiltrados (2006) 8,5
Rate
And this is my code:
File input = new File ("movies.txt");
Scanner in = new Scanner (input);
Scanner reader = new Scanner (System.in);
PrintWriter out = new PrintWriter("MovieList.txt");
System.out.println(in.hasNext()+" "+ in.hasNextLine());
while (in.hasNextLine()){
String word = in.nextLine();
System.out.println(word);
if ( Character.isDigit(word.charAt(0)) )
out.println(word);
}
in.close();
out.close();
}
As you can see, the file includes a list of movies. However, when copying them from the internet, the format in which they were copied is a bit erroneous. My goal is to iterate through each line and if the first character of the line is a number, write it in a new list (generating the correct format). Unfortunately, System.out.println (in.hasNext () + "" + in.hasNextLine ()); they come out as false so the loop never activates.