Package io.microsphere.io
Class FileUtils
- java.lang.Object
-
- io.microsphere.io.FileUtils
-
-
Field Summary
Fields Modifier and Type Field Description static java.io.File[]EMPTY_FILE_ARRAYAn empty immutableFilearray.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intcleanDirectory(java.io.File directory)Cleans a directory without deleting it.static intdeleteDirectory(java.io.File directory)Deletes a directory recursively.static voiddeleteDirectoryOnExit(java.io.File directory)Schedules a directory recursively for deletion on JVM exit.static intforceDelete(java.io.File file)Deletes a file.static voidforceDeleteOnExit(java.io.File file)Schedules a file to be deleted when JVM exits.static java.io.FilegetCanonicalFile(java.io.File file)InvokeFile.getCanonicalFile()without throwingIOException.static java.lang.StringgetFileExtension(java.lang.String fileName)Get File Extensionstatic booleanisSymlink(java.io.File file)static java.io.File[]listFiles(java.io.File directory)List Files from the specified directorystatic java.lang.StringresolveRelativePath(java.io.File parentDirectory, java.io.File targetFile)Resolve Relative Path
-
-
-
Method Detail
-
resolveRelativePath
public static java.lang.String resolveRelativePath(java.io.File parentDirectory, java.io.File targetFile)Resolve Relative Path- Parameters:
parentDirectory- Parent DirectorytargetFile- Target File- Returns:
- If
targetFileis a sub-file ofparentDirectory, resolve relative path, ornull
-
getFileExtension
public static java.lang.String getFileExtension(java.lang.String fileName)
Get File Extension- Parameters:
fileName- the name ofFile- Returns:
- the file extension if found
-
deleteDirectory
public static int deleteDirectory(java.io.File directory) throws java.io.IOExceptionDeletes a directory recursively.- Parameters:
directory- directory to delete- Returns:
- the number of deleted files and directories
- Throws:
java.lang.NullPointerException- if the directory isnulljava.io.IOException- in case deletion is unsuccessful
-
cleanDirectory
public static int cleanDirectory(java.io.File directory) throws java.io.IOExceptionCleans a directory without deleting it.- Parameters:
directory- directory to clean- Throws:
java.lang.NullPointerException- if the directory isnulljava.io.IOException- in case cleaning is unsuccessful
-
forceDelete
public static int forceDelete(java.io.File file) throws java.io.IOExceptionDeletes a file. If file is a directory, delete it and all sub-directories.The difference between File.delete() and this method are:
- A directory to be deleted does not have to be empty.
- You get exceptions when a file or directory cannot be deleted. (java.io.File methods returns a boolean)
- Parameters:
file- file or directory to delete, must not benull- Returns:
- the number of deleted files and directories
- Throws:
java.lang.NullPointerException- if the file isnulljava.io.FileNotFoundException- if the file was not foundjava.io.IOException- in case deletion is unsuccessful
-
forceDeleteOnExit
public static void forceDeleteOnExit(java.io.File file)
Schedules a file to be deleted when JVM exits. If file is directory delete it and all sub-directories.- Parameters:
file- file or directory to delete, must not benull- Throws:
java.lang.NullPointerException- if the file isnull
-
deleteDirectoryOnExit
public static void deleteDirectoryOnExit(java.io.File directory)
Schedules a directory recursively for deletion on JVM exit.- Parameters:
directory- directory to delete, must not benull- Throws:
java.lang.NullPointerException- if the directory isnulljava.io.IOException- in case deletion is unsuccessful
-
listFiles
public static java.io.File[] listFiles(java.io.File directory)
List Files from the specified directory- Parameters:
directory- the specified directory- Returns:
the empty file arrayif the specified directory is not exist or not a directory
-
isSymlink
public static boolean isSymlink(java.io.File file)
-
getCanonicalFile
public static final java.io.File getCanonicalFile(java.io.File file)
InvokeFile.getCanonicalFile()without throwingIOException.- Parameters:
file- theFileinstance- Returns:
File.getCanonicalFile()- Throws:
java.lang.NullPointerException- iffileisnulljava.lang.RuntimeException- If an I/O error occurs, which is possible because the construction of the canonical pathname may require filesystem queries
-
-