Java File Manager


Last year in my AP Computer Science class I built this FileManager class because I found Java's file management methodology frankly irritating. This class makes reading and writing as simple as one function call, and allows for overwriting or appending to a file.

Example

// This code will read file1.txt and then append its contents to file2.txt FileManager file1 = new FileManager("file1.txt"); FileManager file2 = new FileManager("file2.txt"); String read = ""; while(file1.hasNextLine()) { read += "\n" + file1.nextLine(); } file2.append(read); // more compact version /* while(file1.hasNextLine()) { file2.append("\n" + file1.nextLine()); } */

Note

FileManager basically allows your program to totally ignore any exceptions thrown - this is quite useful since it makes reading your code easier, however it does mean you will need to do your own error checking before using FileManager. In other words, if you know the file you're trying to open exists and has read/write access (whatever you need) you're good. But if there's even the slightest question, do those error checks before running FileManager and any of its operations, because errors can go unnoticed if you don't.

Questions, comments, or suggestions? Go ahead and Contact Me

Download: Zip Archive
Size: 1.65kb