Hi I've been asked to write code that will read a text file in the same directory as my .class file. I've written a simple program that reads "input.text" and saves it to a string.
/** Import util for console input **/
import java.util.*;
import java.io.*;
/** Standard Public Declarations **/
public class costing
{
public static void main(String[] args)
{
Scanner inFile = new Scanner(new FileReader("Coursework/input.txt"));
String name = inFile.next();
System.out.println(name);
}
}
Gives the error:
10: error: unreported expection FileNotFoundExcpetion; must be caught or declared to be thrown
I've tried input.txt
in the same folder and one level above but still no luck.
Thanks!!