FileManager is a easy Java extension that makes file managing easier
- Download
FileManager.java
- Create a package named FileManager
- Import the code by using this code(Use different package):
import FileManager.*;
- Then too use it, use this code:
public static void main(String[] args) { // TODO Auto-generated method stub FileManager fm = new FileManager(); }
Now you are finished with the activation!
Note: fm
is going to be use throughout the documentation.
To convert a String to a File use this code
File fPath = fm.toFile("demo/test.html"); //Makes "test.html" to a file
File dPath = fm.toFile("demo"); //Makes "demo" to a directory
To create a file/directory type:
fm.add(dPath,true); //Create a directory
fm.add(fPath); //Creates a file inside the directory
To add context into a file, type:
fm.write(fPath, "Random text"); //Adds "Random text" to the file
To read a file, type:
fm.read(fPath);//Reads lines from the file
To delete files/directories, type:
fm.remove(fPath);//Deletes file
fm.remove(dPath, true);//Deletes Directory
To rename files/directories, type:
File newPath = fm.toFile("demo/updated.html");
fm.rename(fPath,newPath);//Renames "test.html" to "updated.html"
These are methods that will get file informations
This will get the files full name; type:
fm.getFileName(fPath);//Returns the file name
This is get the parent of the file; type:
fm.getParent(fPath);//Returns the files parent
This will get the files path
fm.getPath(fPath);//Returns the files path
This will get the "absolute file" or "absolute path"; type:
fm.getAbsFile(fPath);//Returns the absolute file
fm.getAbsPath(fPath);//Returns the absolute path
This will get the file extension; type:
fm.getExtension(fPath);//Returns file extension
This will get the file name
fm.getName(fPath);//Returns files name
This will get the amount of free space in human-readable format; type:
fm.getFreeSpace(fPath);
This will get the amount of total space in human-readable format; type:
fm.getTotalSpace(fPath);
This will get the amount of usable space in human-readable format; type:
fm.getUsableSpace(fPath);
This will get Canonical File or Canonical Path; type:
fm.getCanonicalFile(fPath);//Returns the CanonicalFile
fm.getCanonicalPath(fPath);//Returns the CanonicalPath
These are extra methods you can use as well
This will compare two filepaths; type:
fm.compare(fPath,dPath);//Returns number of difference
Get files hashcode; type:
fm.hashCode(fPath);//Returns hashcode
Returns a list of directories and/or files; type:
fm.list(dPath);//List files/directories
fm.list(dPath,true);//List files only
Returns a list of directories and/or files based on filter; type:
fm.listFilter(dPath, filter); //Returns filtered directories/files
fm.listFilter(dPath, true, filter); //Returns filtered files
Check if the filepath is; type:
fm.is(fPath, "hidden");//Alloed items: "hidden", "absolute", "dir", "file", "exists"
Check if the filepath can; type:
fm.can(fPath, "read");//Allowed items: "read", "write", or "execute"
Set the filepath permission; type:
fm.set(fPath, "read");//Allowed items: "read", "write", or "execute"
fm.set(fPath, "read", false);//Allowed items: "read", "write", or "execute"
To recieve the users input; type this:
String usersInput = fm.usePrompt("Title");