diff --git a/src/main/java/no/ntnu/idatt1002/demo/data/Budget/FileHandlingBudget.java b/src/main/java/no/ntnu/idatt1002/demo/data/Budget/FileHandlingBudget.java index 9188cd935f3c2ba4ab2d74885146635f96764504..ede36ec1a83a6a29d7165a39d50e28d3bd18b74e 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/data/Budget/FileHandlingBudget.java +++ b/src/main/java/no/ntnu/idatt1002/demo/data/Budget/FileHandlingBudget.java @@ -34,7 +34,7 @@ public class FileHandlingBudget { } /** - * Method for checking if a .register file is empty. + * Method for checking if a .budget file is empty. * * @param fileTitle the name of the file you want to check * @return true or false depending on if file is empty. @@ -46,6 +46,27 @@ public class FileHandlingBudget { } } + /** + * Method for checking if a .budget file is new (no categories) + * or old (has budget categories) + * @param fileTitle The name of the file + * @return True, if the budget is new. Else, returns false + * @throws IOException + */ + public boolean isNewBudget(String fileTitle) throws IOException { + try (BufferedReader br = new BufferedReader( + new FileReader(filePath + fileTitle + fileType))) { + + for (int i = 0; i < 3; ++i) + br.readLine(); + + if (br.readLine() == null) { + return true; + } + } + return false; + } + /** * Method for reading (getting) a Budget from a file. *