Hey guys
I have to write this program for AP Computer Science. It involves writing a main where it brings in a txt file with values, and reads all of them. Eventually, I have to modify it to read the values in to an array. Right now, I can't get it to read the file. My teacher gave us a code snippet to use that will help read the file.
This is my version of the snippet:
import java.util.Scanner;
import java.io.*;
public class main
{
public static void main(String [] args) throws FileNotFoundException
{
File aFile = new File("C:\\Users\\John\\Documents\\values.txt");
Scanner scan = new Scanner(new FileReader(aFile));
int value = 0;
while (scan.hasNext() && value !=999)
{
value=scan.nextInt();
}
scan.close();
}
}
It compiles, but when I run it, it gives an error on the line with Scanner scan...
Any ideas?