So need a method that reads a txt file holding 4 integers (1,2,3,4) and throws an exception. I am think I have the scanner correct... But I want to print the values that the scanner read in my main method. I am not sure how to do that with System.out.println(). The scanner is not in the main method. Here is my code:
public static void scan()
{
String fileInputName = "data.txt";
Scanner sc = null;
try {
sc = new Scanner(new BufferedReader(new FileReader(fileInputName)));
while (sc.hasNextLine())
{
sc.nextInt();
}
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
finally
{
if (sc != null)
sc.close();
}
}