From c83f765c35462c019af7959b64510b1914c9653f Mon Sep 17 00:00:00 2001 From: Carlos Galindo Date: Sun, 12 Jun 2016 16:39:10 +0200 Subject: [PATCH] Config: defaults --- .../es/kauron/jstudy/model/AppConfig.java | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/main/java/es/kauron/jstudy/model/AppConfig.java b/src/main/java/es/kauron/jstudy/model/AppConfig.java index 89a6bd2..c086e48 100644 --- a/src/main/java/es/kauron/jstudy/model/AppConfig.java +++ b/src/main/java/es/kauron/jstudy/model/AppConfig.java @@ -22,19 +22,24 @@ public class AppConfig { } public static void load() { - try { - Scanner in = new Scanner(new File(FILE)); - while (in.hasNextLine()) { - String line = in.nextLine(); - String value = line.substring(line.indexOf('=') + 1); - if (line.matches("repeatWrong=.*")) - repeatWrong = Boolean.parseBoolean(value); - else if (line.matches("showFeedback=.*")) - showFeedback = Boolean.parseBoolean(value); + File file = new File(FILE); + if (!file.exists()) { + repeatWrong = true; + showFeedback = true; + } else + try { + Scanner in = new Scanner(new File(FILE)); + while (in.hasNextLine()) { + String line = in.nextLine(); + String value = line.substring(line.indexOf('=') + 1); + if (line.matches("repeatWrong=.*")) + repeatWrong = Boolean.parseBoolean(value); + else if (line.matches("showFeedback=.*")) + showFeedback = Boolean.parseBoolean(value); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); } - } catch (FileNotFoundException e) { - e.printStackTrace(); - } } public static String printValues() {