/FileManager

FileManager is a easy Java extension that makes file managing easier

Primary LanguageJavaMIT LicenseMIT

FileManager

FileManager is a easy Java extension that makes file managing easier

How to install

  1. Download FileManager.java
  2. Create a package named FileManager
  3. Import the code by using this code(Use different package):
      import FileManager.*;
  4. 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.


Basics

Converting String to File

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

Adding files/directories

To create a file/directory type:

  fm.add(dPath,true); //Create a directory
  fm.add(fPath); //Creates a file inside the directory

Writing in files

To add context into a file, type:

  fm.write(fPath, "Random text"); //Adds "Random text" to the file

Reading files

To read a file, type:

  fm.read(fPath);//Reads lines from the file

Deleting files/directories

To delete files/directories, type:

  fm.remove(fPath);//Deletes file
  fm.remove(dPath, true);//Deletes Directory

Renaming files/directories

To rename files/directories, type:

  File newPath = fm.toFile("demo/updated.html");
  fm.rename(fPath,newPath);//Renames "test.html" to "updated.html"

GET functions

These are methods that will get file informations

getFullName

This will get the files full name; type:

  fm.getFileName(fPath);//Returns the file name

getParent

This is get the parent of the file; type:

  fm.getParent(fPath);//Returns the files parent

getPath

This will get the files path

  fm.getPath(fPath);//Returns the files path

getAbsFile / getAbsPath

This will get the "absolute file" or "absolute path"; type:

  fm.getAbsFile(fPath);//Returns the absolute file
  fm.getAbsPath(fPath);//Returns the absolute path

getExtension

This will get the file extension; type:

  fm.getExtension(fPath);//Returns file extension

getName

This will get the file name

  fm.getName(fPath);//Returns files name

getFreeSpace

This will get the amount of free space in human-readable format; type:

  fm.getFreeSpace(fPath);

getTotalSpace

This will get the amount of total space in human-readable format; type:

  fm.getTotalSpace(fPath);

getUsableSpace

This will get the amount of usable space in human-readable format; type:

  fm.getUsableSpace(fPath);

getCanFile / getCanPath

This will get Canonical File or Canonical Path; type:

  fm.getCanonicalFile(fPath);//Returns the CanonicalFile
fm.getCanonicalPath(fPath);//Returns the CanonicalPath

Extras

These are extra methods you can use as well

compare

This will compare two filepaths; type:

  fm.compare(fPath,dPath);//Returns number of difference

hashCode

Get files hashcode; type:

  fm.hashCode(fPath);//Returns hashcode

list

Returns a list of directories and/or files; type:

  fm.list(dPath);//List files/directories
  fm.list(dPath,true);//List files only

list w/ filter

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

is

Check if the filepath is; type:

  fm.is(fPath, "hidden");//Alloed items: "hidden", "absolute", "dir", "file", "exists"

can

Check if the filepath can; type:

  fm.can(fPath, "read");//Allowed items: "read", "write", or "execute"

set

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"

Users Input

To recieve the users input; type this:

String usersInput = fm.usePrompt("Title");