Class FileLoader


  • public class FileLoader
    extends Object
    Class that can read and write files onto the drive
    Author:
    Darius Dinger
    • Constructor Detail

      • FileLoader

        public FileLoader()
    • Method Detail

      • readFile

        public static String[] readFile​(String path,
                                        boolean lineBreak)
                                 throws FileNotFoundException,
                                        IOException
        Reading a file from drive into a string array
        Parameters:
        path - Path to the file relative to the application
        lineBreak - If true, the strings in the result array will have an \n at the end
        Returns:
        String that contains the file content
        Throws:
        FileNotFoundException - Throws if file could not be found
        IOException - Throws if an I/O error occurs
      • writeFile

        public static void writeFile​(String path,
                                     String[] data)
                              throws IOException
        Writes an string array ascii decoded into a file. Adding line breaks ('\n') at the end of every line
        Parameters:
        path - Path of the output file relative to the application
        data - Data to write (lines, strings)
        Throws:
        IOException - Throws if lines cant be written
      • writeBinaryFile

        public static <T> void writeBinaryFile​(String path,
                                               T data)
                                        throws IOException
        Writes an object binary decoded into a file. The object class has to implement the serializable interface!
        Type Parameters:
        T - Type of the object to write
        Parameters:
        path - Path of the output file relative to application
        data - Data to write (object of type T)
        Throws:
        IOException - Throws if object cant be written
      • getResource

        public static String[] getResource​(String path,
                                           boolean lineBreak)
        Reading a ascii resource from resources into a string array
        Parameters:
        path - Path to the resource
        lineBreak - If true, the strings in the result array will have an \n at the end
        Returns:
        String that contains the resource content (ascii)