From 8e626d8097727afa7cbcda58547aebc0944fedff Mon Sep 17 00:00:00 2001 From: Kristian Knarvik Date: Sat, 15 Aug 2020 20:55:29 +0200 Subject: [PATCH] Fixes a FileNotFoundException caused by the version file not existing --- .../server/ServerVersionContainer.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/knarcraft/minecraftserverlauncher/server/ServerVersionContainer.java b/src/main/java/net/knarcraft/minecraftserverlauncher/server/ServerVersionContainer.java index 7d31d0e..d0ed61f 100644 --- a/src/main/java/net/knarcraft/minecraftserverlauncher/server/ServerVersionContainer.java +++ b/src/main/java/net/knarcraft/minecraftserverlauncher/server/ServerVersionContainer.java @@ -88,12 +88,18 @@ public class ServerVersionContainer implements java.io.Serializable { * Tries to save the state of this server version container */ public void saveState() { + File saveFile = new File(versionFile); PrintWriter file; try { + if (!saveFile.exists()) { + if (!saveFile.createNewFile()) { + throw new FileNotFoundException("Unable to create version file"); + } + } file = new PrintWriter(versionFile); file.println(this.toString()); file.close(); - } catch (FileNotFoundException e) { + } catch (IOException e) { e.printStackTrace(); } }