Part of my current project is to read a .txt log file, if that log file doesn't exist in it's normal path, I want to open up a JavaFX FileChooser, and let the user point to the file. But in it's current state it pops up the file chooser window, and after I've pointed to the location of the .txt file, it just idles the entire program.
In the class that extends Application:
public class GetDirectory extends Application {
@Override
public void start(final Stage primaryStage) {
FileChooser fileChooser = new FileChooser();
FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("TXT files (*.txt)", "*.txt");
fileChooser.getExtensionFilters().add(extFilter);
File file = fileChooser.showOpenDialog(primaryStage);
main.gamedata.LogReader logReader = new LogReader();
logReader.setPathTemp(file.getAbsolutePath());
primaryStage.close();
}
}
In the method in another class where I need the path to the file:
private List<String> getHearthstoneLogContent(String pathToFile) {
try {
File file = new File(pathToFile);
if (file.exists() && !file.isDirectory()) {
return Files.readAllLines(Paths.get(pathToFile));
} else {
// The out_log.txt file does not exist, we should let the user choose the path.
Application.launch(GetDirectory.class);
System.out.println("sup");
return Files.readAllLines(Paths.get(pathTemp));
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
However "sup" never gets printed to the console.
What I have tried
I thought it might be because the Application doesn't close, so I tried using:
primaryStage.close();
PlatformImpl.tkExit();
Platform.exit();
But we can't use that since it produces an IllegalStateException: Toolkit has exited.
What I don't want to do
I don't wanna wrap all my code inside JavaFX since I only need it for such a small task.
If you want to take a closer look at the project in question: http://github.com/nymann/DeckSniffer/