- Tested Minecraft Versions:
- 1.10FileIOYAML is old. This is common knowledge for a lot but not most developers now. How about a new system for reading from files? This library lets you either use the built-in storage system with basic variables or you can even create your own system with your own system for reading and custom syntax that you can parse in your own way programmatically!
- Built-in variable system!
- FileReader class that allows you to read from a file using the built-in variable system or read the entire file as a string and parse it using your own syntax on one line!
- FileWriter class that uses a builder-type structure allowing you to write multiple variables or multiple different custom pieces of data into the file on one line!
- FileWriter class also features 3 different reading modes: APPEND (adds to existing data in file), WRITE (overwrites existing data / creates new file) and DELETE (simply deletes the file once the apply function is executed)!
- FileUtils class that features functions such as functions that allow you to return a list of all the files in a directory and all of it's sub-directories. More coming soon!Code (Text):Constructor:
public FileWriter(File file, FileWriterMode mode) throws IOException, FileNotFoundException
The above constructor is the constructor for the FileWriter, takes in the file to be written to and the mode to write using from either APPEND, WRITE or DELETE.
Throws an IOException if when reading the contents of the file, the API runs into an error. Throws a FileNotFoundException if the file doesn't exist in any writing mode besides WRITE mode whereby the exception will not be thrown.Code (Text):Function:
public FileWriter apply() throws IOException
The above function applies any changes made using the APPEND mode, overwrites / creates the file in WRITE mode and deletes the file in DELETE mode.
Throws an IOException if an error occurs whilst writing to the file.Code (Text):Function:
public FileWriter write(String fileEdit)
This function simply adds on to the fileEdits string whatever is inputted into the parameters, used for custom syntax reading / writing.Code (Text):Function:
public FileWriter(String name, Object x)
This function doesn't actually have an Object parameter as the second parameter however has either int, float, double, String or boolean as the second parameter but to condense the documentation I decided to use Object instead. This function writes to the fileEdits string in the built-in variable format of: %variableNameHere%value%END_variableNameHere%\nCode (Text):Getters:
public File getFile()
public FileWriterMode getMode()
public String getFileEdits()
The first getter simply gets the file being written to, the second getter gets the enumerator for the file writing mode and the third getter gets the string that contains the current file edits.
public FileReader(File file) throws IOException, FileNotFoundException
The above constructor is the constructor for the FileReader, takes in the file to read from.
Throws an IOException if when reading the contents of the file, the API runs into an error. Throws a FileNotFoundException if the file doesn't exist.Code (Text):Function:
public void updateFileContents() throws IOException
This function updates the string that contains the file contains.
Throws an IOException if when reading the contents of the file, the API runs into an error.Code (Text):Getter:
public String getFileContents()
This getter returns the contents of the file as a single string.Code (Text):Function:
public Object readObjectType(String name)
This function returns the object type that corresponds with the type told in the function. The current types supported are: readInteger, readFloat, readDouble, readString, readBoolean which return their respective types. This is used for the built-in variables system.
Implicitly throws an InvalidFormatException if the data-type given to parse by the API is incorrect.
public static ArrayList<File> getAllFilesInDirectory(File directory)
This function returns all the files in the directory inputted into the parameters and all of it's sub-directories.