What I am trying to do is read data from a file and only print the integers out. I am trying not to use an arraylist for this, It works flawlessly with an arraylist but I'm trying to do this another way.The problem is my code is showing the error the scanner is not a symbol.
error: cannot find symbol
data[i++] = scannernextInt();
^
error: cannot find symbol
scanner.next();
^
Can you explain why this error is showing up?
What I have currently:
public static void main(String[] args) {
int[] data = new int[8];
int i = 0;
try
{
Scanner scanner = new Scanner(new File("data.txt"));
}
catch (FileNotFoundException e)
{
System.out.println(" File does not exist.");
scanner = null;
}
while (scanner.hasNext())
{
if(scanner.hasNextInt())
{
data[i++] = scannernextInt();
System.out.print(data[i]);
}
else
{
scanner.next();
}
}