From 5ce58f067e7d9001e42525b3386a14224495bca7 Mon Sep 17 00:00:00 2001 From: Harry Linrui XU <xulr0820@hotmail.com> Date: Wed, 19 Apr 2023 23:45:00 +0200 Subject: [PATCH] Added method for clearing SelectedBudget.current file --- .../demo/data/Budget/FileHandlingSelectedBudget.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/no/ntnu/idatt1002/demo/data/Budget/FileHandlingSelectedBudget.java b/src/main/java/no/ntnu/idatt1002/demo/data/Budget/FileHandlingSelectedBudget.java index 85e95294..067abebb 100644 --- a/src/main/java/no/ntnu/idatt1002/demo/data/Budget/FileHandlingSelectedBudget.java +++ b/src/main/java/no/ntnu/idatt1002/demo/data/Budget/FileHandlingSelectedBudget.java @@ -22,7 +22,7 @@ public class FileHandlingSelectedBudget { selectedBudgetFileType))) { return br.readLine(); } catch (IOException ioException) { - throw new IOException("File: CurrentFile.txt does not exist", ioException); + throw new IOException("File: SelectedBudget.current does not exist", ioException); } } @@ -36,6 +36,16 @@ public class FileHandlingSelectedBudget { } } + public static void clearSelectedBudget() throws IOException { + try (BufferedWriter bw = new BufferedWriter(new FileWriter(filePath + "SelectedBudget" + + selectedBudgetFileType))) { + bw.write(""); + System.out.println("Current file is: "); + } catch (IOException ex) { + throw new IOException("Error writing to file: " + "SelectedBudget.current"); + } + } + public static boolean isSelectedBudgetEmpty(String fileTitle) throws IOException { try (BufferedReader br = new BufferedReader(new FileReader(filePath + "SelectedBudget" + selectedBudgetFileType))) { -- GitLab