public class FileUtil extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
APPLICATION_DIRECTORY |
static java.lang.String |
separator |
static char |
separatorChar |
Constructor and Description |
---|
FileUtil() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
backup(java.lang.String filename)
Backup the specified file.
|
static java.lang.String |
cleanPath(java.lang.String filePath)
Cleanup the file path (replace some problematic character by "_")
|
static boolean |
copy(java.io.File src,
java.io.File dst,
boolean force,
boolean recursive)
Copy src to dst with the specified parameters.
|
static boolean |
copy(java.io.File src,
java.io.File dst,
boolean force,
boolean wantHidden,
boolean recursive)
Deprecated.
Use
copy(File, File, boolean, boolean) instead |
static boolean |
copy(java.lang.String src,
java.lang.String dst,
boolean force,
boolean recursive)
Copy src to dst.
|
static boolean |
copy(java.lang.String src,
java.lang.String dst,
boolean force,
boolean wantHidden,
boolean recursive)
Deprecated.
Use
copy(String, String, boolean, boolean) instead |
static boolean |
createDir(java.io.File dir) |
static boolean |
createDir(java.lang.String dirname) |
static java.io.File |
createFile(java.io.File file) |
static java.io.File |
createFile(java.lang.String filename) |
static boolean |
createLink(java.lang.String path,
java.lang.String target)
Create a symbolic link file
|
static boolean |
delete(java.io.File f,
boolean recursive) |
static boolean |
delete(java.lang.String path,
boolean recursive) |
static boolean |
ensureParentDirExist(java.io.File file) |
static void |
ensureParentDirExist(java.lang.String filename) |
static boolean |
exist(java.lang.String path)
Deprecated.
use
exists(String) instead |
static boolean |
exists(java.lang.String path)
Return true if the file described by specified path exists
|
static java.io.File[] |
explode(java.io.File[] files,
java.io.FileFilter filter,
boolean recursive,
boolean wantHidden)
Transform all directory entries by their sub files list
|
static java.util.List<java.io.File> |
explode(java.util.List<java.io.File> files,
boolean recursive,
boolean wantHidden)
Deprecated.
Use
explode(List, FileFilter, boolean, boolean) instead. |
static java.util.List<java.io.File> |
explode(java.util.List<java.io.File> files,
java.io.FileFilter filter,
boolean recursive,
boolean wantHidden)
Transform all directory entries by their sub files list
|
static java.lang.String |
getApplicationDirectory()
Returns the path where the application is located (current directory).
|
static java.lang.String |
getCurrentDirectory()
Deprecated.
Use
getApplicationDirectory() instead. |
static java.io.File[] |
getDirectories(java.io.File file,
java.io.FileFilter filter,
boolean recursive,
boolean wantHidden)
Get directory list from specified directory applying the specified parameters
|
static java.lang.String |
getDirectory(java.lang.String path)
Return directory information from specified path
getDirectory("/file.txt") --> "/" getDirectory("D:/temp/file.txt") --> "D:/temp/" getDirectory("D:/temp/") --> "D:/temp/" getDirectory("D:/temp") --> "D:/" getDirectory("C:file.txt") --> "C:" getDirectory("file.txt") --> "" getDirectory("file") --> "" getDirectory(null) --> "" |
static java.lang.String |
getDirectory(java.lang.String path,
boolean separator)
Return directory information from specified path
getDirectory("/file.txt") --> "/" getDirectory("D:/temp/file.txt") --> "D:/temp/" getDirectory("D:/temp/") --> "D:/temp/" getDirectory("D:/temp") --> "D:/" getDirectory("C:file.txt") --> "C:" getDirectory("file.txt") --> "" getDirectory("file") --> "" getDirectory(null) --> "" |
static java.lang.String |
getDrive(java.lang.String path)
Return drive / mount point from specified path
getDrive("D:/temp/file.txt") --> "D:" getDrive("D:/temp") --> "D:" getDrive("C:file.txt") --> "C:" getDrive("file.txt") --> "" |
static java.lang.String |
getFileExtension(java.lang.String path,
boolean withDot)
Return filename extension information from specified path
Dot character is returned depending the withDot flag value getFileExtension("/file.txt") --> "(.)txt)" getFileExtension("D:/temp/file.txt.old") --> "(.)old" getFileExtension("C:/win/dir2/file") --> "" getFileExtension(".txt") --> "(.)txt)" getFileExtension(null) --> "" |
static java.util.ArrayList<java.io.File> |
getFileList(java.io.File file,
boolean recursive,
boolean wantHidden)
Deprecated.
|
static java.util.ArrayList<java.io.File> |
getFileList(java.io.File file,
boolean recursive,
boolean wantDirectory,
boolean wantHidden)
Deprecated.
|
static java.util.ArrayList<java.io.File> |
getFileList(java.io.File file,
java.io.FileFilter filter,
boolean recursive,
boolean wantHidden)
Deprecated.
|
static java.util.ArrayList<java.io.File> |
getFileList(java.io.File file,
java.io.FileFilter filter,
boolean recursive,
boolean wantDirectory,
boolean wantHidden)
Deprecated.
|
static java.util.ArrayList<java.io.File> |
getFileList(java.lang.String path,
boolean recursive,
boolean wantHidden)
Deprecated.
|
static java.util.ArrayList<java.io.File> |
getFileList(java.lang.String path,
boolean recursive,
boolean wantDirectory,
boolean wantHidden)
Deprecated.
|
static java.util.ArrayList<java.io.File> |
getFileList(java.lang.String path,
java.io.FileFilter filter,
boolean recursive,
boolean wantHidden)
Deprecated.
|
static java.util.ArrayList<java.io.File> |
getFileList(java.lang.String path,
java.io.FileFilter filter,
boolean recursive,
boolean wantDirectory,
boolean wantHidden)
Deprecated.
|
static java.util.ArrayList<java.lang.String> |
getFileListAsString(java.lang.String path,
boolean recursive,
boolean wantHidden)
Deprecated.
|
static java.util.ArrayList<java.lang.String> |
getFileListAsString(java.lang.String path,
boolean recursive,
boolean wantDirectory,
boolean wantHidden)
Deprecated.
|
static java.util.ArrayList<java.lang.String> |
getFileListAsString(java.lang.String path,
java.io.FileFilter filter,
boolean recursive,
boolean wantHidden)
Deprecated.
|
static java.util.ArrayList<java.lang.String> |
getFileListAsString(java.lang.String path,
java.io.FileFilter filter,
boolean recursive,
boolean wantDirectory,
boolean wantHidden)
Deprecated.
|
static java.lang.String |
getFileName(java.lang.String path)
Return filename information from specified path.
|
static java.lang.String |
getFileName(java.lang.String path,
boolean withExtension)
Return filename information from specified path.
|
static java.io.File[] |
getFiles(java.io.File directory,
java.io.FileFilter filter,
boolean recursive,
boolean wantDirectory,
boolean wantHidden)
Returns an array of file denoting content of specified directory and parameters.
|
static java.io.File[] |
getFiles(java.io.File folder,
java.lang.String extension,
boolean ignoreExtensionCase,
boolean recursive)
Get file list from specified folder applying the specified parameters.
|
static java.lang.String[] |
getFiles(java.lang.String directory,
java.io.FileFilter filter,
boolean recursive,
boolean wantDirectory,
boolean wantHidden)
Returns an array of file path denoting content of specified directory and parameters
(String format).
|
static java.lang.String[] |
getFiles(java.lang.String folder,
java.lang.String extension,
boolean ignoreExtensionCase,
boolean recursive)
Get file list from specified folder applying the specified parameters.
|
static java.lang.String |
getGenericPath(java.lang.String path)
Transform any system specific path in java generic path form.
|
static java.lang.String |
getTempDirectory()
Returns default temporary directory.
|
static boolean |
isDirectory(java.lang.String path)
Return true if the specified file is a directory
|
static boolean |
isLink(java.io.File file)
Return true if the specified file is a link
Be careful, it does work in almost case, but not all |
static boolean |
isLink(java.lang.String path)
Return true if the specified file is a link
Be careful, it does work in almost case, but not all |
static byte[] |
load(java.io.File file,
boolean displayError) |
static byte[] |
load(java.lang.String path,
boolean displayError) |
static boolean |
move(java.io.File src,
java.io.File dst,
boolean force)
Deprecated.
Use
rename(File, File, boolean) instead |
static boolean |
move(java.io.File src,
java.io.File dst,
boolean force,
boolean wantHidden)
Deprecated.
Use
move(File, File, boolean) instead |
static boolean |
move(java.lang.String src,
java.lang.String dst,
boolean force)
Deprecated.
Use
rename(String, String, boolean) instead |
static boolean |
move(java.lang.String src,
java.lang.String dst,
boolean force,
boolean wantHidden)
Deprecated.
Use
move(String, String, boolean) instead |
static boolean |
rename(java.io.File src,
java.io.File dst,
boolean force)
Rename the specified 'src' file to 'dst' file.
|
static boolean |
rename(java.io.File src,
java.io.File dst,
boolean force,
boolean wantHidden)
Deprecated.
Use
rename(File, File, boolean) instead |
static boolean |
rename(java.lang.String src,
java.lang.String dst,
boolean force)
Rename the specified
src file to dst file. |
static boolean |
rename(java.lang.String src,
java.lang.String dst,
boolean force,
boolean wantHidden)
Deprecated.
Use
rename(String, String, boolean) instead |
static boolean |
save(java.io.File file,
byte[] data,
boolean displayError) |
static boolean |
save(java.lang.String path,
byte[] data,
boolean displayError) |
static java.lang.String |
setExtension(java.lang.String path,
java.lang.String extension)
Change path extension.
|
static java.util.List<java.io.File> |
toFiles(java.util.List<java.lang.String> paths)
Transform the specified list of path to file.
|
static java.io.File[] |
toFiles(java.lang.String[] paths)
Transform the specified list of path to file.
|
static java.lang.String[] |
toPaths(java.io.File[] files)
Transform the specified list of file to path.
|
static java.util.List<java.lang.String> |
toPaths(java.util.List<java.io.File> files)
Transform the specified list of file to path.
|
public static final char separatorChar
public static final java.lang.String separator
public static final java.lang.String APPLICATION_DIRECTORY
public FileUtil()
public static java.lang.String cleanPath(java.lang.String filePath)
public static java.lang.String getGenericPath(java.lang.String path)
public static java.lang.String getTempDirectory()
public static java.lang.String setExtension(java.lang.String path, java.lang.String extension)
public static void ensureParentDirExist(java.lang.String filename)
public static boolean ensureParentDirExist(java.io.File file)
public static boolean createDir(java.lang.String dirname)
public static boolean createDir(java.io.File dir)
public static java.io.File createFile(java.lang.String filename)
public static java.io.File createFile(java.io.File file)
public static java.io.File[] toFiles(java.lang.String[] paths)
public static java.util.List<java.io.File> toFiles(java.util.List<java.lang.String> paths)
public static java.lang.String[] toPaths(java.io.File[] files)
public static java.util.List<java.lang.String> toPaths(java.util.List<java.io.File> files)
public static boolean createLink(java.lang.String path, java.lang.String target)
public static byte[] load(java.lang.String path, boolean displayError)
public static byte[] load(java.io.File file, boolean displayError)
public static boolean save(java.lang.String path, byte[] data, boolean displayError)
public static boolean save(java.io.File file, byte[] data, boolean displayError)
public static java.lang.String getApplicationDirectory()
@Deprecated public static java.lang.String getCurrentDirectory()
getApplicationDirectory()
instead.public static java.lang.String getDrive(java.lang.String path)
public static java.lang.String getDirectory(java.lang.String path, boolean separator)
public static java.lang.String getDirectory(java.lang.String path)
public static java.lang.String getFileName(java.lang.String path)
public static java.lang.String getFileName(java.lang.String path, boolean withExtension)
public static java.lang.String getFileExtension(java.lang.String path, boolean withDot)
public static boolean rename(java.lang.String src, java.lang.String dst, boolean force)
src
file to dst
file.
Return false if the method failed.src
- the source filename we want to rename from.dst
- the destination filename we want to rename to.force
- If set to true
the destination file is overwritten if it was already
existing.File.renameTo(File)
@Deprecated public static boolean rename(java.lang.String src, java.lang.String dst, boolean force, boolean wantHidden)
rename(String, String, boolean)
insteadpublic static boolean rename(java.io.File src, java.io.File dst, boolean force)
File.renameTo(File)
@Deprecated public static boolean rename(java.io.File src, java.io.File dst, boolean force, boolean wantHidden)
rename(File, File, boolean)
instead@Deprecated public static boolean move(java.lang.String src, java.lang.String dst, boolean force)
rename(String, String, boolean)
instead@Deprecated public static boolean move(java.lang.String src, java.lang.String dst, boolean force, boolean wantHidden)
move(String, String, boolean)
instead@Deprecated public static boolean move(java.io.File src, java.io.File dst, boolean force)
rename(File, File, boolean)
instead@Deprecated public static boolean move(java.io.File src, java.io.File dst, boolean force, boolean wantHidden)
move(File, File, boolean)
insteadpublic static boolean copy(java.lang.String src, java.lang.String dst, boolean force, boolean recursive)
src
- source file or directorydst
- destination file or directoryforce
- force copy to previous existing filerecursive
- also copy sub directory@Deprecated public static boolean copy(java.lang.String src, java.lang.String dst, boolean force, boolean wantHidden, boolean recursive)
copy(String, String, boolean, boolean)
insteadpublic static boolean copy(java.io.File src, java.io.File dst, boolean force, boolean recursive)
src
- source file or directorydst
- destination file or directoryforce
- force copy to previous existing filerecursive
- also copy sub directory@Deprecated public static boolean copy(java.io.File src, java.io.File dst, boolean force, boolean wantHidden, boolean recursive)
copy(File, File, boolean, boolean)
insteadpublic static java.lang.String backup(java.lang.String filename)
filename
- file to backupnull
public static java.io.File[] explode(java.io.File[] files, java.io.FileFilter filter, boolean recursive, boolean wantHidden)
@Deprecated public static java.util.List<java.io.File> explode(java.util.List<java.io.File> files, boolean recursive, boolean wantHidden)
explode(List, FileFilter, boolean, boolean)
instead.public static java.util.List<java.io.File> explode(java.util.List<java.io.File> files, java.io.FileFilter filter, boolean recursive, boolean wantHidden)
public static java.io.File[] getFiles(java.io.File folder, java.lang.String extension, boolean ignoreExtensionCase, boolean recursive)
public static java.lang.String[] getFiles(java.lang.String folder, java.lang.String extension, boolean ignoreExtensionCase, boolean recursive)
public static java.io.File[] getDirectories(java.io.File file, java.io.FileFilter filter, boolean recursive, boolean wantHidden)
public static java.io.File[] getFiles(java.io.File directory, java.io.FileFilter filter, boolean recursive, boolean wantDirectory, boolean wantHidden)
directory
- The directory we want to retrieve content.filter
- A file filter.filter
is null
then all pathnames are accepted.
Otherwise, a pathname satisfies the filter if and only if the value true
results when the
FileFilter.accept(java.io.File)
method of the
filter is invoked on the pathname.recursive
- If true
then content from sub folder is also returned.wantDirectory
- If true
then directory entries are also returned.wantHidden
- If true
then file or directory with hidden
attribute are
also returned.File.listFiles(FileFilter)
public static java.lang.String[] getFiles(java.lang.String directory, java.io.FileFilter filter, boolean recursive, boolean wantDirectory, boolean wantHidden)
directory
- The directory we want to retrieve content.filter
- A file filter.filter
is null
then all files are accepted.
Otherwise, a file satisfies the filter if and only if the value true
results when the
FileFilter.accept(java.io.File)
method of the
filter is invoked on the pathname.recursive
- If true
then content from sub folder is also returned.wantDirectory
- If true
then directory entries are also returned.wantHidden
- If true
then file or directory with hidden
attribute are
also returned.@Deprecated public static java.util.ArrayList<java.io.File> getFileList(java.lang.String path, java.io.FileFilter filter, boolean recursive, boolean wantDirectory, boolean wantHidden)
getFiles(File, FileFilter, boolean, boolean, boolean)
instead.@Deprecated public static java.util.ArrayList<java.io.File> getFileList(java.io.File file, java.io.FileFilter filter, boolean recursive, boolean wantDirectory, boolean wantHidden)
getFiles(File, FileFilter, boolean, boolean, boolean)
instead.@Deprecated public static java.util.ArrayList<java.io.File> getFileList(java.lang.String path, java.io.FileFilter filter, boolean recursive, boolean wantHidden)
getFiles(File, FileFilter, boolean, boolean, boolean)
instead.@Deprecated public static java.util.ArrayList<java.io.File> getFileList(java.io.File file, java.io.FileFilter filter, boolean recursive, boolean wantHidden)
getFiles(File, FileFilter, boolean, boolean, boolean)
instead.@Deprecated public static java.util.ArrayList<java.io.File> getFileList(java.lang.String path, boolean recursive, boolean wantDirectory, boolean wantHidden)
getFiles(File, FileFilter, boolean, boolean, boolean)
instead.@Deprecated public static java.util.ArrayList<java.io.File> getFileList(java.io.File file, boolean recursive, boolean wantDirectory, boolean wantHidden)
getFiles(File, FileFilter, boolean, boolean, boolean)
instead.@Deprecated public static java.util.ArrayList<java.io.File> getFileList(java.io.File file, boolean recursive, boolean wantHidden)
getFiles(File, FileFilter, boolean, boolean, boolean)
instead.@Deprecated public static java.util.ArrayList<java.io.File> getFileList(java.lang.String path, boolean recursive, boolean wantHidden)
getFiles(File, FileFilter, boolean, boolean, boolean)
instead.@Deprecated public static java.util.ArrayList<java.lang.String> getFileListAsString(java.lang.String path, java.io.FileFilter filter, boolean recursive, boolean wantDirectory, boolean wantHidden)
getFiles(String, FileFilter, boolean, boolean, boolean)
instead.@Deprecated public static java.util.ArrayList<java.lang.String> getFileListAsString(java.lang.String path, boolean recursive, boolean wantDirectory, boolean wantHidden)
getFiles(String, FileFilter, boolean, boolean, boolean)
instead.@Deprecated public static java.util.ArrayList<java.lang.String> getFileListAsString(java.lang.String path, java.io.FileFilter filter, boolean recursive, boolean wantHidden)
getFiles(String, FileFilter, boolean, boolean, boolean)
instead.@Deprecated public static java.util.ArrayList<java.lang.String> getFileListAsString(java.lang.String path, boolean recursive, boolean wantHidden)
getFiles(String, FileFilter, boolean, boolean, boolean)
instead.@Deprecated public static boolean exist(java.lang.String path)
exists(String)
insteadpublic static boolean exists(java.lang.String path)
public static boolean isDirectory(java.lang.String path)
public static boolean isLink(java.lang.String path) throws java.io.IOException
java.io.IOException
public static boolean isLink(java.io.File file) throws java.io.IOException
java.io.IOException
public static boolean delete(java.lang.String path, boolean recursive)
public static boolean delete(java.io.File f, boolean recursive)