Package de.coreengine.asset
Class FileLoader
- java.lang.Object
-
- de.coreengine.asset.FileLoader
-
public class FileLoader extends Object
Class that can read and write files onto the drive- Author:
- Darius Dinger
-
-
Constructor Summary
Constructors Constructor Description FileLoader()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String[]
getResource(String path, boolean lineBreak)
Reading a ascii resource from resources into a string arraystatic <T> T
readBinaryFile(String path)
Reading a binary file from drive into an objectstatic String[]
readFile(String path, boolean lineBreak)
Reading a file from drive into a string arraystatic <T> void
writeBinaryFile(String path, T data)
Writes an object binary decoded into a file.static void
writeFile(String path, String[] data)
Writes an string array ascii decoded into a file.
-
-
-
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 applicationlineBreak
- 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 foundIOException
- 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 applicationdata
- Data to write (lines, strings)- Throws:
IOException
- Throws if lines cant be written
-
readBinaryFile
public static <T> T readBinaryFile(String path) throws FileNotFoundException, IOException, ClassNotFoundException, ClassCastException
Reading a binary file from drive into an object- Type Parameters:
T
- Type of the object to read- Parameters:
path
- Path of the binary file to read- Returns:
- Readed object as T
- Throws:
FileNotFoundException
- Throws if file could no be foundIOException
- Throws if file could not be loadedClassNotFoundException
- Throws if the objects class from the file could not be foundClassCastException
- Throws if object from file couldnt parsed into T
-
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 applicationdata
- 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 resourcelineBreak
- If true, the strings in the result array will have an \n at the end- Returns:
- String that contains the resource content (ascii)
-
-