Мой код заключается в следующем:
Код: Выделить всё
public void mainMethod() throws FileNotFoundException, IOException {
// Creating an instance of this class so we can call the various methods
FileNotFoundGUI FNFGUI = new FileNotFoundGUI();
// Finding the current path the program is running on then backing up and navigating
// to the properties file to set the default fileLocation to the spot chosen by the
// user after they finished navigating the files to where they stored Tracking program
String rootPath = Thread.currentThread().getContextClassLoader().getResource("").getPath();
rootPath = (rootPath.substring(1, rootPath.length() - 5) + "\\src\\DataParsing\\config.Properties").replace("/","\\");
Properties prop = new Properties();
// System.out.println(rootPath);
//prop.setProperty("FileLocation", "C:\\Users\\nawcm\\Desktop\\Trickery\\Tracking Program\\");
System.out.println(prop.getProperty("FileLocation"));
if (foundFile == false) {
if (prop.getProperty("FileLocation") == null) {
System.out.println("Null Property");
FNFGUI.NoFile();
} else {
File testFile = new File(prop.getProperty("FileLocation") + "Information Folders\\FoundAircraft.txt");
try (Scanner fileLook = new Scanner(testFile)) {
foundFile = true;
} catch (FileNotFoundException e) {
System.out.println("File Not Found: " + e);
FNFGUI.NoFile();
}
}
if (foundFile == true) {
stGui();
}
}
}
Код: Выделить всё
FileLocation=C:\\Users\\nawcm\\Desktop\\Trickery\\Tracking Program\\Причина этого находится в специальном классе mainMethod, потому что в другом вопросе, похожем на мой, говорится, что не следует использовать статический класс, чтобы избежать проблем. В противном случае я не знаю, что здесь делать.
Подробнее здесь: https://stackoverflow.com/questions/785 ... ific-class
Мобильная версия