Im working on a Minesweeper clone and I want the user to be able to save their fastest solve times to a .txt file. I have it set up and working inside Eclipse with the following code in my i/o class:
public static final String RECORD_FILE_NAME = "records/records.txt";
public static String readRecords() {
String records = "";
try {
Scanner scan = new Scanner(new FileInputStream(RECORD_FILE_NAME));
while (scan.hasNextLine()) {
records = records + scan.nextLine() + "\n";
}
scan.close();
} catch (Exception e) {
throw new IllegalArgumentException("Invalid file");
}
return records;
}
public static void writeRecords(String records, String fileName) {
try {
PrintStream writer = new PrintStream(new File(fileName));
writer.print(records);
} catch (Exception e) {
throw new IllegalArgumentException("Unable to save file.");
}
}
However, after exporting the project as a Runnable JAR File, the readRecords() method throws the IllegalArgumentException from inside the catch block. So, how should I set up file i/o so that it works outside of Eclipse? Any help is greatly appreciated, thanks!