import java.io.*;
import java.util.Scanner;
public class Test {
/**
* @param args
*/
public static void main(String[] args) throws FileNotFoundException {
File test = new File("test.txt");
Scanner read = new Scanner (test);
String input;
input = read.next();
System.out.println (input);
}
}
When I run this code, I get this error
Exception in thread "main" java.io.FileNotFoundException: test.txt (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.util.Scanner.<init>(Unknown Source)
at Test.main(Test.java:9)
I have already created the text file and it is right in the project folder but it is not finding it.
EDIT
InputStream file = getClass().getResourceAsStream("highScore.txt");
BufferedReader br = new BufferedReader (new InputStreamReader(file,"UTF-8"));
String text;
text = br.readLine();
while (text!=null) {
System.out.println (text);
}
I tried this but I got a NullPointerException error
This is for an applet.