FileInput Help/Advice
- by user559142
I have a fileinput class. It has a string parameter in the constructor to load the filename supplied. However it just exits if the file doesn't exist. I would like it to output a message if the file doesn't exist - but not sure how....
Here is the class:
public class FileInput extends Input {
/**
* Construct <code>FileInput</code> object given a file name.
*/
public FileInput(final String fileName) {
try {
scanner = new Scanner(new FileInputStream(fileName));
} catch (FileNotFoundException e) {
System.err.println("File " + fileName + " could not be found.");
System.exit(1);
}
}
/**
* Construct <code>FileInput</code> object given a file name.
*/
public FileInput(final FileInputStream fileStream) {
super(fileStream);
}
}
And its implementation:
private void loadFamilyTree() {
out.print("Enter file name: ");
String fileName = in.nextLine();
FileInput input = new FileInput(fileName);
family.load(input);
input.close();
}