I am a beginner of java, and when I following the display 2.12 of Absolute Java. The console shows there is thread in 'main. I put the text file in the root directory of my program. And I also have double check for the code. I have no idea how to fix it. I am using eclipse to code in the macOS and java is the newest version. Thanks for your help The code shows like this:
import java.util.Scanner;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
public class TextFileDemo
{
public static void main(String[] args)
{
Scanner fileIn = null;
try
{
fileIn = new Scanner(new FileInputStream("player.rtf"));
}
catch (FileNotFoundException e)
{
System.out.println("file not found.");
System.exit(0);
}
int highscore;
String name;
System.out.println("Text left to read? " + fileIn.hasNextLine());
highscore = fileIn.nextInt();
fileIn.nextLine();
name = fileIn.nextLine();
System.out.println("Name: " + name);
System.out.println("High score: " + highscore);
System.out.println("Text left to read? " + fileIn.hasNextLine());
fileIn.close();
}
And this is my console display: