Class FileHandling

java.lang.Object
no.ntnu.idatt1002.demo.data.economics.FileHandling

public class FileHandling extends Object
FileHandling is a class for writing and reading ItemRegister-objects to and from a file.
Author:
andreas
  • Constructor Details

    • FileHandling

      public FileHandling()
  • Method Details

    • writeItemRegisterToFile

      public static <T extends Item> void writeItemRegisterToFile(ItemRegister<T> itemRegister, String fileDestination) throws IOException
      Method for writing (adding) an ItemRegister to a file.
      Type Parameters:
      T - Subclass of item, either expense or income.
      Parameters:
      itemRegister - the ItemRegister you want to write to a file.
      fileDestination - the path and name of the file you want to check
      Throws:
      IOException - if an input or output exception occurred.
    • isEmpty

      public static boolean isEmpty(String fileDestination) throws IOException
      Method for checking if a .register file is empty.
      Parameters:
      fileDestination - the path and name of the file you want to check
      Returns:
      true or false depending on if file is empty.
      Throws:
      IOException - if an input or output exception occurred.
    • readIncomeRegisterFromFile

      public static IncomeRegister readIncomeRegisterFromFile(String fileDestination) throws IOException
      Method for reading (getting) an IncomeRegister from a file.
      Parameters:
      fileDestination - the name of the file you want to read from.
      Returns:
      the IncomeRegister from the file.
      Throws:
      IOException - if an input or output exception occurred.
    • readExpenseRegisterFromFile

      public static ExpenseRegister readExpenseRegisterFromFile(String fileDestination) throws IOException
      Method for reading (getting) an ExpenseRegister from a file.
      Parameters:
      fileDestination - the name of the file you want to read from.
      Returns:
      the ExpenseRegister from the file.
      Throws:
      IOException - if an input or output exception occurred