-
Notifications
You must be signed in to change notification settings - Fork 0
Class Jutilas
Package jutilas.core
File Jutilas.java
Jutilas is the class that contains the generic functions to develop an application.
This class implements the singleton pattern, so to get the Jutilas instance you need to use the getInstance()
method.
Example:
Jutilas.getInstance()
.
-
- void copyFile(String filePath, String toPath, CopyOption... copyOptions)
- void renameFile(String filePath, String newName)
- String readFile(String filePath)
- String readFile(File file)
- String readRandomAccessFile(File file)
- String getLastRowsFile(String filePath, int numRows)
- void recursiveDelete(String filePath)
- void emptyDirectory(String... path)
- boolean isEmptyDirectory(File file)
This method order a String list while ignoring the difference between upper and lower case.
Example:
List<String> list = new List<String>(); // insert elements on list Jutilas.getInstance().sortIgnoreCase(list);
throws FileException
This method sets a configuration, based on key and value, and saves it to the file.
Use the class java.util.Properties
.
Parameters:
- filePath, path to the file where you want to save the configurations
- param, key of configuration to be save
- value, value of configuration
- head, header to be inserted in the file
Exceptions:
- FileException, exception thrown if an I/O error is returned while working on the file
Example:
Jutilas.getInstance().setConf("app.conf", "key", "val", "Configuration file");
throws FileException
This method get a configuration saved in it to the file.
Use the class java.util.Properties
.
Return: Return the value of configuration required.
Parameters:
- filePath, path to the file where have save the configurations
- param, key of configuration to be get
Exceptions:
- FileException, exception thrown if an I/O error is returned while working on the file
Example:
String conf = Jutilas.getInstance().getConf("app.conf", "key");
This method create a path formatted for OS.
Return:
Return the string of the path formatted for OS.
Parameters:
- path, list of directory
Example:
String path = Jutilas.getInstance().getStringPath("path", "to", "file", "file.txt");
throws IOException
This method restart the java application.
Use the class java.util.Properties
.
Exceptions:
- IOException, exception thrown if an I/O error is returned while restart the app
Example:
Jutilas.getInstance().restartApp();
throws IOException, URISyntaxException
This method opens the default browser of the operating system, which will load the URL passed as an argument.
Return:
Return true if success, false if java.awt.Desktop
is not supported.
Parameters:
- URL, url to be open in browser
Exceptions:
- URISyntaxException, exception thrown if past url syntax is not correct
- IOException, exception thrown if the call to the operating system returns an input/output error
Example:
Jutilas.getInstance().openBrowser("https://github.com/d3v4s");
throws IOException
This method opens the default application of the operating system, for open the file passed.
Return:
Return true if success, false if java.awt.Desktop
is not supported.
Parameters:
- path, path to file to be opened
Exceptions:
- IOException, exception thrown if the call to the operating system returns an input/output error
Example:
Jutilas.getInstance().openFileFromOS("my", "dir", "file.txt"); // open the file editor
throws FileException
This method copy a file.
Parameters:
- filePath, path to file to be copied
- toPath, path where to copy the file
-
copyOptions*, copy options to pass to the function
Files.copy()
Exceptions:
- FileException, exception thrown if the copy of the file returns a I/O errors
Example:
Jutilas.getInstance().copyFile("path/from/file.txt", "path/to/file.txt");
throws FileException
This method rename a file.
Parameters:
- filePath, path to file to be renamed
- newName, new file name
Exceptions:
- FileException, exception thrown if the raname of the file returns a I/O errors
Example:
Jutilas.getInstance().renameFile("my/dir/file.txt", "new_name.txt");
throws FileException
This method read a file.
Return:
Return a String containing the read text.
Parameters:
- filePath, path to file to be read
Exceptions:
- FileException, exception thrown if reading the file returns a I/O errors
Example:
String txt = Jutilas.getInstance().readFile("my/dir/file.txt");
throws FileException
This method read a file.
Return:
Return a String containing the read text.
Parameters:
- file, file to be read
Exceptions:
- FileException, exception thrown if reading the file returns a I/O errors
Example:
File file = new File("path/to/file.txt"); String txt = Jutilas.getInstance().readFile(file);
throws FileException
This method read a file using the java.io.RandomAccessFile
class.
Return:
Return a String containing the read text.
Parameters:
- file, file to be read
Exceptions:
- FileException, exception thrown if reading the file returns a I/O errors
Example:
File file = new File("path/to/file.txt"); String txt = Jutilas.getInstance().readRandomAccessFile(file);
throws FileException
This method read the last row of file, using the java.io.RandomAccessFile
class.
Return:
Return a String containing the last row of file.
Parameters:
- filePath, path to file to be read
- numRows, number of last rows to be read
Exceptions:
- FileException, exception thrown if reading the file returns a I/O errors
Example:
String txt = Jutilas.getInstance().getLastRowsFile("path/to/file.txt", 50);
This method delete files, instead if a directory recursively deletes all the files and directories inside it.
Return:
Return a String containing the last row of file.
Parameters:
- filePath, path to file to be deleted
Example:
Jutilas.getInstance().recursiveDelete("path/to/dir");
throws FileException
This method delete all files and directories,inside the directory path passed.
Parameters:
- path, path to directory to be empty
Example:
Jutilas.getInstance().emptyDirectory("path/to/dir");
This method check if the directory is empty.
Return:
Return true if the directory is empty, otherwise false.
Parameters:
- file, file to be checked
Example:
Jutilas.getInstance().isEmptyDirectory("path/to/dir");