public final class FileUtils extends Object
Note that methods which request information about files from the system has their own caches to improve performance. If you will need to clear that cache simply call the corresponding clearCache method, for example: For method "isHidden" you will need to call "clearIsHiddenCache" and all cached values will be reset.
| Modifier and Type | Field and Description |
|---|---|
static FileComparator |
FILE_COMPARATOR
File comparator.
|
static long |
GB
Number of bytes in 1 gigabyte.
|
static long |
KB
Number of bytes in 1 kilobyte.
|
static long |
MB
Number of bytes in 1 megabyte.
|
static long |
PB
Number of bytes in 1 petabyte.
|
static long |
TB
Number of bytes in 1 terabyte.
|
| Modifier and Type | Method and Description |
|---|---|
static String |
appropriateFileName(String text)
Returns appropriate file name based on provided text.
|
static String |
appropriateFileName(String text,
String replacement)
Returns appropriate file name based on provided text.
|
static String |
canonicalPath(File file)
Returns file canonical path if its possible or absolute path otherwise.
|
static void |
clearDirectory(File dir)
Deletes all child files and directories for specified directory.
|
static void |
clearDisplayFileCreationDateCache()
Clears cache for "getDisplayFileCreationDate" method.
|
static void |
clearDisplayFileCreationDateCache(String absolutePath)
Clears cache for "getDisplayFileCreationDate" method for specified file path.
|
static void |
clearDisplayFileModificationDateCache()
Clears cache for "getDisplayFileModificationDate" method.
|
static void |
clearDisplayFileModificationDateCache(String absolutePath)
Clears cache for "getDisplayFileModificationDate" method for specified file path.
|
static void |
clearDisplayFileNameCache()
Clears cache for "getDisplayFileName" method.
|
static void |
clearDisplayFileNameCache(String absolutePath)
Clears cache for "getDisplayFileName" method for specified file path.
|
static void |
clearFileCaches(File file)
Clears all caches for specified file.
|
static void |
clearFileCaches(String path)
Clears all caches for file under the specified path.
|
static void |
clearFileDescriptionCache()
Clears cache for "getFileDescription" method.
|
static void |
clearFileDescriptionCache(String absolutePath)
Clears cache for "getFileDescription" method for specified file path.
|
static void |
clearFilesCaches(File... files)
Clears all caches for specified files.
|
static void |
clearFileTypeDescriptionCache()
Clears cache for "getFileTypeDescription" method.
|
static void |
clearFileTypeDescriptionCache(String absolutePath)
Clears cache for "getFileTypeDescription" method for specified file path.
|
static void |
clearIsCdDriveCache()
Clears cache for "isCdDrive" method.
|
static void |
clearIsCdDriveCache(String absolutePath)
Clears cache for "isCdDrive" method for specified file path.
|
static void |
clearIsComputerCache()
Clears cache for "isComputer" method.
|
static void |
clearIsComputerCache(String absolutePath)
Clears cache for "isComputer" method for specified file path.
|
static void |
clearIsDirectoryCache()
Clears cache for "isDirectory" method.
|
static void |
clearIsDirectoryCache(String absolutePath)
Clears cache for "isDirectory" method for specified file path.
|
static void |
clearIsDriveCache()
Clears cache for "isDrive" method.
|
static void |
clearIsDriveCache(String absolutePath)
Clears cache for "isDrive" method for specified file path.
|
static void |
clearIsFileCache()
Clears cache for "isFile" method.
|
static void |
clearIsFileCache(String absolutePath)
Clears cache for "isFile" method for specified file path.
|
static void |
clearIsHiddenCache()
Clears cache for "isHidden" method.
|
static void |
clearIsHiddenCache(String absolutePath)
Clears cache for "isHidden" method for specified file path.
|
static String |
computeMD5(InputStream inputStream)
Returns MD5 for the data provided by
InputStream. |
static String |
computeMD5(InputStream inputStream,
int bufferLength)
Returns MD5 for the data provided by
InputStream and uses a buffer of the specified length. |
static String |
computeMD5(Resource resource)
Returns MD5 for specified
File content. |
static String |
computeMD5(Resource resource,
int bufferLength)
Returns MD5 for specified
File content and uses a buffer of the specified length. |
static String |
computeMD5(String data)
Returns MD5 for specified
String data. |
static String |
computeMD5(String data,
int bufferLength)
Returns MD5 for specified
String data and uses a buffer of the specified length. |
static boolean |
containsFile(List files,
File file)
Returns whether list of files or file paths contains the specified file or not.
|
static boolean |
copyDirectory(File srcDir,
File dstDir)
Copies src directory content into dst directory and returns whether operation succeed or not.
|
static boolean |
copyDirectory(File srcDir,
File dstDir,
boolean stopOnFail)
Copies src directory content into dst directory and returns whether operation succeed or not.
|
static boolean |
copyDirectory(String src,
String dst)
Copies src directory content into dst directory and returns whether operation succeed or not.
|
static boolean |
copyDirectory(String src,
String dst,
boolean stopOnFail)
Copies src directory content into dst directory and returns whether operation succeed or not.
|
static boolean |
copyFile(FileChannel srcFC,
FileChannel dstFC)
Copies file data from source file channel into destination file channel.
|
static boolean |
copyFile(File srcFile,
File dstFile)
Copies source file content into destination file.
|
static boolean |
copyFile(String src,
String dst)
Copies source file content into destination file.
|
static FileDescription |
createFileDescription(File file,
String fileSize)
Returns complete file description.
|
static void |
deleteFile(File file)
Deletes file or directory completely.
|
static void |
deleteFiles(List files)
Deletes all specified files.
|
static void |
deleteFiles(Object... files)
Deletes all specified files.
|
static void |
displayFileName(JTextComponent editor,
File file)
Sets file name as text and selects its name part in any text component.
|
static File |
downloadFile(String url,
File dstFile)
Downloads file from the specified url to destination file and returns it if download succeed.
|
static File |
downloadFile(String url,
File dstFile,
boolean encodeUrl,
String contentType,
int timeout)
Downloads file from the specified url to destination file and returns it if download succeed.
|
static File |
downloadFile(String url,
File dstFile,
boolean encodeUrl,
String contentType,
int timeout,
FileDownloadListener listener)
Downloads file from the specified url to destination file and returns it if download succeed.
|
static File |
downloadFile(String url,
File dstFile,
FileDownloadListener listener)
Downloads file from the specified url to destination file and returns it if download succeed.
|
static File |
downloadFile(String url,
String dst,
boolean encodeUrl,
String contentType,
int timeout)
Downloads file from the specified url to destination file and returns it if download succeed.
|
static File |
downloadFile(String url,
String dst,
boolean encodeUrl,
String contentType,
int timeout,
FileDownloadListener listener)
Downloads file from the specified url to destination file and returns it if download succeed.
|
static boolean |
ensureDirectoryExists(File dir)
Returns true if directory exists or was successfully created during this check, false otherwise.
|
static boolean |
ensureDirectoryExists(String dir)
Returns true if directory exists or was successfully created during this check, false otherwise.
|
static boolean |
equals(File file1,
File file2)
Returns whether both files represent the same path in file system or not.
|
static boolean |
equals(List<File> files1,
List<File> files2)
Returns whether both list of files have equal files in the same positions or not.
|
static List<File> |
filterFiles(Collection<File> files,
AbstractFileFilter fileFilter)
Returns filtered files list.
|
static List<File> |
filterFiles(Collection<File> files,
Filter<File> fileFilter)
Returns filtered files list.
|
static List<File> |
findFilesRecursively(File dir,
FileFilter filter)
Returns list of files accepted by file filter found in the specified directory and its subdirectories.
|
static List<File> |
findFilesRecursively(File dir,
FileFilter filter,
List<File> found)
Returns list of files accepted by file filter found in the specified directory and its subdirectories.
|
static List<File> |
findFilesRecursively(File dir,
List<String> extension)
Returns list of files with specified extensions found in the specified directory and its subdirectories.
|
static List<File> |
findFilesRecursively(File dir,
List<String> extension,
boolean withDot)
Returns list of files with specified extensions found in the specified directory and its subdirectories.
|
static List<File> |
findFilesRecursively(File dir,
List<String> extension,
boolean withDot,
List<File> found)
Returns list of files with specified extensions found in the specified directory and its subdirectories.
|
static List<File> |
findFilesRecursively(String dir,
FileFilter filter)
Returns list of files accepted by file filter found in the specified directory and its subdirectories.
|
static List<File> |
findFilesRecursively(String dir,
FileFilter filter,
List<File> found)
Returns list of files accepted by file filter found in the specified directory and its subdirectories.
|
static List<File> |
findFilesRecursively(String dir,
List<String> extension)
Returns list of files with specified extensions found in the specified directory and its subdirectories.
|
static List<File> |
findFilesRecursively(String dir,
List<String> extension,
boolean withDot)
Returns list of files with specified extensions found in the specified directory and its subdirectories.
|
static List<File> |
findFilesRecursively(String dir,
List<String> extension,
boolean withDot,
List<File> found)
Returns list of files with specified extensions found in the specified directory and its subdirectories.
|
static String |
getAvailableName(File dir,
String name)
Returns available file name in the specified directory and which is similar the specified name.
|
static String |
getAvailableName(List<String> existingNames,
String name)
Returns available file name that is not contained in the existing names list.
|
static String |
getAvailableName(String dir,
String name)
Returns available file name in the specified directory and which is similar the specified name.
|
static File |
getDesktop()
Returns desktop directory if one can be found.
|
static String |
getDesktopPath()
Returns desktop directory path if one can be found.
|
static File[] |
getDiskRoots()
Returns array of available system disks.
|
static String |
getDisplayFileCreationDate(File file)
Returns file modification date to display.
|
static String |
getDisplayFileModificationDate(File file)
Returns file modification date to display.
|
static String |
getDisplayFileName(File file)
Returns file name to display.
|
static String |
getDisplayFileSize(File file)
Returns file size to display.
|
static String |
getDisplayFileSize(File file,
int digits)
Returns file size to display.
|
static FileDescription |
getFileDescription(File file,
String fileSize)
Returns complete file description.
|
static String |
getFileExtPart(File file,
boolean withDot)
Returns file extension either with or without dot.
|
static String |
getFileExtPart(String name,
boolean withDot)
Returns file extension either with or without dot.
|
static Icon |
getFileIcon(File file)
Returns system file icon.
|
static Icon |
getFileIcon(File file,
boolean large)
Returns either large or small system file icon.
|
static String |
getFileNamePart(File file)
Returns file name without extension.
|
static String |
getFileNamePart(String name)
Returns file name without extension.
|
static List<File> |
getFilePath(File file)
Returns list of files contained in path of the specified file.
|
static int |
getFileSize(String url)
Returns file size, located at the specified url.
|
static int |
getFileSize(URL url)
Returns file size, located at the specified url.
|
static String |
getFileSizeString(long size)
Returns file size to display.
|
static String |
getFileSizeString(long size,
int digits)
Returns file size to display.
|
static String |
getFileTypeDescription(File file)
Returns file type description.
|
static Icon |
getIconResource(Class nearClass,
String resource)
Returns resource icon.
|
static Icon |
getIconResource(Class nearClass,
String resource,
float opacity)
Returns resource icon with the specified opacity.
|
static File |
getJarLocationFile(Class jarClass)
Returns JAR location File for the specified class.
|
static URL |
getJarLocationURL(Class jarClass)
Returns JAR location URL for the specified class.
|
static File |
getParent(File file)
Returns parent
File. |
static String |
getProperFileName(String name)
Returns a valid for any file system file name based on specified name.
|
static String |
getRelativePath(File file,
File folder)
Returns file path relative to specified folder or canonical path if file is not inside that folder.
|
static String |
getShortFileName(String name)
Returns shortened file name.
|
static String |
getShortFileName(String name,
int length)
Returns shortened to the specified length file name.
|
static Icon |
getStandardFileIcon(boolean large,
String extension,
float opacity)
Returns either large or small icon for the specified extension from a standard icons set.
|
static Icon |
getStandardFileIcon(File file,
boolean large)
Returns either large or small file icon from a standard icons set.
|
static Icon |
getStandardFileIcon(File file,
boolean large,
boolean enabled)
Returns either large or small file icon from a standard icons set.
|
static List<String> |
getSubPaths(File dir)
Returns list of all file paths in this directory and all subdirectories.
|
static List<String> |
getSubPaths(File dir,
String path)
Returns list of all file paths in this directory and all subdirectories.
|
static List<String> |
getSubPaths(File dir,
String path,
List<String> paths)
Returns list of all file paths in this directory and all subdirectories.
|
static List<String> |
getSubPaths(String dir)
Returns list of all file paths in this directory and all subdirectories.
|
static FileFilter |
getSwingFileFilter(AbstractFileFilter fileFilter)
Returns actual Swing file filter from the specified filter.
|
static File |
getSystemRoot()
Returns first available file system root.
|
static File[] |
getSystemRoots()
Returns array of available file system roots.
|
static File |
getSystemTemp()
Returns system directory for temporary files.
|
static String |
getSystemTempPath()
Returns path to system directory for temporary files.
|
static File |
getTopParent(File file)
Returns top not-null parent for the specified file.
|
static File |
getUserHome()
Returns user home directory.
|
static String |
getUserHomePath()
Returns path to user home directory.
|
static File |
getWorkingDirectory()
Returns application working directory.
|
static String |
getWorkingDirectoryPath()
Returns application working directory.
|
static boolean |
grantExecutePermissions(File file)
Grants file execution permission for all users for specified file.
|
static boolean |
isCdDrive(File file)
Returns whether the specified file points to system CD/DVD/Bluray drive or not.
|
static boolean |
isComputer(File file)
Returns whether the specified file points to system hard drive or not.
|
static boolean |
isDirectory(File file)
Returns whether the specified file is directory or not.
|
static boolean |
isDrive(File file)
Returns whether the specified file points to system hard drive or not.
|
static boolean |
isFile(File file)
Returns whether the specified file is actually a file (and not a directory, disk or some system folder) or not.
|
static boolean |
isFileAccepted(File file,
List<AbstractFileFilter> filters)
Returns whether any of the specified file filters accept the file or not.
|
static boolean |
isHidden(File file)
Returns whether the specified file is hidden or not.
|
static boolean |
isIllegalFileNameChar(char c)
Returns whether the specified character is illegal or not.
|
static boolean |
isNameEditable(File file)
Returns whether specified file's name can be edited.
|
static boolean |
isParent(File parent,
File child)
Returns whether the specified child file is one of parent file children or not.
|
static File[] |
listFiles(File directory)
Returns directory files array or empty array (instead of null) if no files present.
|
static File[] |
listFiles(File directory,
FileFilter fileFilter)
Returns directory files array or empty array (instead of null) if no files present.
|
static File[] |
listFiles(File directory,
Filter<File> fileFilter)
Returns directory files array or empty array (instead of null) if no files present.
|
static File |
normalize(File file)
Returns normalized file without redundant parts in its path.
|
static String |
readToString(InputStream inputStream)
Returns content read from the input stream.
|
static String |
readToString(InputStream inputStream,
String encoding)
Returns content read from the input stream.
|
static String |
readToString(Reader reader)
Returns content read from the specified reader.
|
static String |
readToString(Resource resource)
|
static String |
readToString(Resource resource,
String encoding)
|
static File[] |
sortFiles(File[] files)
Returns sorted array of files.
|
static List<File> |
sortFiles(List<File> files)
Returns sorted list of files.
|
static List<File> |
toFilesList(Object... object)
Converts objects array into list of files.
|
static WebTimer |
trackFile(File file,
SystemFileListener listener)
Starts tracking file for possible changes.
|
static WebTimer |
trackFile(File file,
SystemFileListener listener,
long delay)
Starts tracking file for possible changes.
|
static AbstractFileFilter |
transformFileFilter(FileFilter fileFilter)
Returns transformed file filter.
|
static AbstractFileFilter |
transformFileFilter(FileFilter fileFilter)
Returns transformed file filter.
|
static void |
writeStringToFile(String text,
File file)
Writes text to the specified file overwriting any content inside the file.
|
static void |
writeStringToFile(String text,
File file,
String encoding)
Writes text to the specified file overwriting any content inside the file.
|
public static final long KB
public static final long MB
public static final long GB
public static final long TB
public static final long PB
public static final FileComparator FILE_COMPARATOR
@Nullable public static URL getJarLocationURL(@NotNull Class jarClass)
jarClass - any class from that JAR@Nullable public static File getJarLocationFile(@NotNull Class jarClass)
jarClass - any class from that JARpublic static void clearFilesCaches(@Nullable File... files)
files - files to processpublic static void clearFileCaches(@Nullable File file)
file - file to processpublic static void clearFileCaches(@NotNull String path)
path - file path@NotNull public static List<File> getFilePath(@Nullable File file)
For example if you have some file that points to some local file: "C:\folder\file.txt" You will get this list of files: "C:\", "C:\folder\", "C:\folder\file.txt"
file - file to process@NotNull public static String getRelativePath(@NotNull File file, @NotNull File folder)
file - file to get relative path tofolder - one of file's parent folderspublic static boolean isNameEditable(@NotNull File file)
file - file to editpublic static void displayFileName(@NotNull JTextComponent editor, @NotNull File file)
editor - text editor to processfile - file to process@NotNull public static File getSystemTemp()
@NotNull public static String getSystemTempPath()
public static boolean grantExecutePermissions(@NotNull File file)
file - file for permissions change@Nullable public static File normalize(@Nullable File file)
file - file to normalize@Nullable public static File getSystemRoot()
@NotNull public static File[] getSystemRoots()
@NotNull public static File[] getDiskRoots()
@NotNull public static File[] listFiles(@NotNull File directory)
directory - directory to look into@NotNull public static File[] listFiles(@NotNull File directory, @Nullable Filter<File> fileFilter)
directory - directory to look intofileFilter - file filter@NotNull public static File[] listFiles(@NotNull File directory, @Nullable FileFilter fileFilter)
directory - directory to look intofileFilter - file filter@NotNull public static String computeMD5(@NotNull String data)
String data.data - file to processString data@NotNull public static String computeMD5(@NotNull String data, int bufferLength)
String data and uses a buffer of the specified length.data - file to processbufferLength - buffer lengthString data@NotNull public static String computeMD5(@NotNull Resource resource)
File content.@NotNull public static String computeMD5(@NotNull Resource resource, int bufferLength)
File content and uses a buffer of the specified length.@NotNull public static String computeMD5(@NotNull InputStream inputStream)
InputStream.inputStream - data stream to processInputStream@NotNull public static String computeMD5(@NotNull InputStream inputStream, int bufferLength)
InputStream and uses a buffer of the specified length.inputStream - data stream to processbufferLength - buffer lengthInputStream@NotNull public static File getWorkingDirectory()
@NotNull public static String getWorkingDirectoryPath()
@NotNull public static File getUserHome()
@NotNull public static String getUserHomePath()
@Nullable public static File getDesktop()
@Nullable public static String getDesktopPath()
public static boolean equals(@Nullable File file1, @Nullable File file2)
file1 - first file to be comparedfile2 - second file to be comparedpublic static boolean equals(@NotNull List<File> files1, @NotNull List<File> files2)
files1 - first files list to be comparedfiles2 - second files list to be comparedpublic static boolean containsFile(@NotNull List files, @NotNull File file)
files - list of files to search infile - file to look forpublic static boolean isFileAccepted(@NotNull File file, @Nullable List<AbstractFileFilter> filters)
file - file to processfilters - file filters list@NotNull public static String getProperFileName(@NotNull String name)
name - name to processpublic static boolean isIllegalFileNameChar(char c)
c - character to process@NotNull public static String canonicalPath(File file)
file - file to process@Nullable public static File getParent(@NotNull File file)
File.
Unlike File.getParentFile() it doesn't fail on cases when native parent is null.
Whenever native parent is null this method will fallback to File.getParent() path usage.@Nullable public static File getTopParent(@NotNull File file)
file - file to processpublic static boolean isParent(@Nullable File parent, @Nullable File child)
parent - parent filechild - child file@NotNull public static String getFileNamePart(@Nullable File file)
file - file to process@NotNull public static String getFileNamePart(@Nullable String name)
name - file name to trim@NotNull public static String getFileExtPart(@Nullable File file, boolean withDot)
file - file to processwithDot - whether return the extension with dot, or not@NotNull public static String getFileExtPart(@Nullable String name, boolean withDot)
name - file name to processwithDot - whether return the extension with dot, or not@NotNull public static String getShortFileName(@Nullable String name)
name - file name to shorten@NotNull public static String getShortFileName(@Nullable String name, int length)
name - file name to shortenlength - maximum allowed file name length@Nullable public static List<File> sortFiles(@Nullable List<File> files)
files - list of files to sort@Nullable public static File[] sortFiles(@Nullable File[] files)
files - array of files to sort@NotNull public static String getAvailableName(@NotNull String dir, @NotNull String name)
dir - directory path to checkname - file name to check@NotNull public static String getAvailableName(@NotNull File dir, @NotNull String name)
dir - directory to checkname - file name to check@NotNull public static String getAvailableName(@NotNull List<String> existingNames, @NotNull String name)
existingNames - list of existing file namesname - file name to check@NotNull public static List<File> toFilesList(@Nullable Object... object)
object - file objectpublic static void deleteFiles(@NotNull Object... files)
files - files to deletepublic static void deleteFiles(@NotNull List files)
files - files to deletepublic static void deleteFile(@NotNull File file)
file - file to deletepublic static void clearDirectory(@NotNull File dir)
dir - directory to clear@NotNull public static AbstractFileFilter transformFileFilter(@NotNull FileFilter fileFilter)
fileFilter - IO file filter@NotNull public static AbstractFileFilter transformFileFilter(@NotNull FileFilter fileFilter)
fileFilter - Swing file filter@Nullable public static FileFilter getSwingFileFilter(@Nullable AbstractFileFilter fileFilter)
fileFilter - WebLaF file filter@NotNull public static List<File> filterFiles(@NotNull Collection<File> files, @NotNull AbstractFileFilter fileFilter)
files - files collection to filterfileFilter - file filter@NotNull public static List<File> filterFiles(@NotNull Collection<File> files, @NotNull Filter<File> fileFilter)
files - files collection to filterfileFilter - file filter@NotNull public static FileDescription createFileDescription(@NotNull File file, @Nullable String fileSize)
file - file to processfileSize - file size@NotNull public static String getDisplayFileSize(@NotNull File file)
file - file to process@NotNull public static String getDisplayFileSize(@NotNull File file, int digits)
file - file to processdigits - number of digits after the dotpublic static String getFileSizeString(long size)
size - size of the file@NotNull public static String getFileSizeString(long size, int digits)
size - size of the filedigits - number of digits after the dotpublic static boolean copyDirectory(@NotNull String src, @NotNull String dst)
src - source directory pathdst - destination directory pathpublic static boolean copyDirectory(@NotNull String src, @NotNull String dst, boolean stopOnFail)
src - source directory pathdst - destination directory pathstopOnFail - whether to stop copy operation if any exception occurs or notpublic static boolean copyDirectory(@NotNull File srcDir, @NotNull File dstDir)
srcDir - source directorydstDir - destination directorypublic static boolean copyDirectory(@NotNull File srcDir, @NotNull File dstDir, boolean stopOnFail)
srcDir - source directorydstDir - destination directorystopOnFail - whether to stop copy operation if any exception occurs or notpublic static boolean copyFile(@Nullable String src, @Nullable String dst)
src - source file pathdst - destination file pathpublic static boolean copyFile(@Nullable File srcFile, @Nullable File dstFile)
srcFile - source filedstFile - destination filepublic static boolean copyFile(@NotNull FileChannel srcFC, @NotNull FileChannel dstFC)
srcFC - source file channeldstFC - destination file channel@NotNull public static String readToString(@NotNull Resource resource, @NotNull String encoding)
@NotNull public static String readToString(@NotNull InputStream inputStream)
inputStream - text content input stream@NotNull public static String readToString(@NotNull InputStream inputStream, @NotNull String encoding)
inputStream - text content input streamencoding - stream data encoding@NotNull public static String readToString(@NotNull Reader reader)
reader - text content readerpublic static void writeStringToFile(@NotNull String text, @NotNull File file)
text - text to writefile - file to write text intopublic static void writeStringToFile(@NotNull String text, @NotNull File file, @NotNull String encoding)
text - text to writefile - file to write text intoencoding - file encoding@NotNull public static List<String> getSubPaths(@NotNull String dir)
dir - path of directory to process@NotNull public static List<String> getSubPaths(@NotNull File dir)
dir - directory to process@NotNull public static List<String> getSubPaths(@NotNull File dir, @NotNull String path)
dir - directory to processpath - path to current position@NotNull public static List<String> getSubPaths(@NotNull File dir, @NotNull String path, @NotNull List<String> paths)
dir - directory to processpath - path to current positionpaths - list of collected paths@NotNull public static File downloadFile(@NotNull String url, @NotNull File dstFile)
url - file source urldstFile - destination file@NotNull public static File downloadFile(@NotNull String url, @NotNull File dstFile, @Nullable FileDownloadListener listener)
url - file source urldstFile - destination filelistener - file download process listener@NotNull public static File downloadFile(@NotNull String url, @NotNull String dst, boolean encodeUrl, @Nullable String contentType, int timeout)
url - file source urldst - destination file pathencodeUrl - whether encode the source url or notcontentType - content type limitationtimeout - connection and read timeout@NotNull public static File downloadFile(@NotNull String url, @NotNull String dst, boolean encodeUrl, @Nullable String contentType, int timeout, @Nullable FileDownloadListener listener)
url - file source urldst - destination file pathencodeUrl - whether encode the source url or notcontentType - content type limitationtimeout - connection and read timeoutlistener - file download process listener@NotNull public static File downloadFile(@NotNull String url, @NotNull File dstFile, boolean encodeUrl, @Nullable String contentType, int timeout)
url - file source urldstFile - destination fileencodeUrl - whether encode the source url or notcontentType - content type limitationtimeout - connection and read timeout@NotNull public static File downloadFile(@NotNull String url, @NotNull File dstFile, boolean encodeUrl, @Nullable String contentType, int timeout, @Nullable FileDownloadListener listener)
url - file source urldstFile - destination fileencodeUrl - whether encode the source url or notcontentType - content type limitationtimeout - connection and read timeoutlistener - file download process listenerpublic static int getFileSize(@NotNull String url)
url - file location urlpublic static int getFileSize(@NotNull URL url)
url - file location url@NotNull public static List<File> findFilesRecursively(@NotNull String dir, @NotNull List<String> extension)
dir - path to directory to processextension - file extensions list@NotNull public static List<File> findFilesRecursively(@NotNull File dir, @NotNull List<String> extension)
dir - directory to processextension - file extensions list@NotNull public static List<File> findFilesRecursively(@NotNull String dir, @NotNull List<String> extension, boolean withDot)
dir - path to directory to processextension - file extensions listwithDot - whether extensions contain dot or not@NotNull public static List<File> findFilesRecursively(@NotNull File dir, @NotNull List<String> extension, boolean withDot)
dir - directory to processextension - file extensions listwithDot - whether extensions contain dot or not@NotNull public static List<File> findFilesRecursively(@NotNull String dir, @NotNull List<String> extension, boolean withDot, @NotNull List<File> found)
dir - path to directory to processextension - file extensions listwithDot - whether extensions contain dot or notfound - list in which found files should be stored@NotNull public static List<File> findFilesRecursively(@NotNull File dir, @NotNull List<String> extension, boolean withDot, @NotNull List<File> found)
dir - directory to processextension - file extensions listwithDot - whether extensions contain dot or notfound - list in which found files should be stored@NotNull public static List<File> findFilesRecursively(@NotNull String dir, @NotNull FileFilter filter)
dir - path to directory to processfilter - file filter@NotNull public static List<File> findFilesRecursively(@NotNull File dir, @NotNull FileFilter filter)
dir - directory to processfilter - file filter@NotNull public static List<File> findFilesRecursively(@NotNull String dir, @NotNull FileFilter filter, @NotNull List<File> found)
dir - path to directory to processfilter - file filterfound - list in which found files should be stored@NotNull public static List<File> findFilesRecursively(@NotNull File dir, @NotNull FileFilter filter, @NotNull List<File> found)
dir - directory to processfilter - file filterfound - list in which found files should be storedpublic static boolean ensureDirectoryExists(@Nullable String dir)
dir - path to directory to checkpublic static boolean ensureDirectoryExists(@Nullable File dir)
dir - directory to checkpublic static void clearIsDriveCache()
public static void clearIsDriveCache(@NotNull String absolutePath)
absolutePath - path to clear file isDrive mark cache forpublic static boolean isDrive(@NotNull File file)
file - file to processpublic static void clearIsComputerCache()
public static void clearIsComputerCache(@NotNull String absolutePath)
absolutePath - path to clear file isComputer mark cache forpublic static boolean isComputer(@NotNull File file)
file - file to processpublic static void clearIsCdDriveCache()
public static void clearIsCdDriveCache(@NotNull String absolutePath)
absolutePath - path to clear file isCdDrive mark cache forpublic static boolean isCdDrive(@NotNull File file)
file - file to processpublic static void clearIsFileCache()
public static void clearIsFileCache(@NotNull String absolutePath)
absolutePath - path to clear file isFile mark cache forpublic static boolean isFile(@Nullable File file)
file - file to processpublic static void clearIsDirectoryCache()
public static void clearIsDirectoryCache(@NotNull String absolutePath)
absolutePath - path to clear file isDirectory mark cache forpublic static boolean isDirectory(@Nullable File file)
file - file to processpublic static void clearIsHiddenCache()
public static void clearIsHiddenCache(@NotNull String absolutePath)
absolutePath - path to clear file hidden mark cache forpublic static boolean isHidden(@Nullable File file)
file - file to processpublic static void clearFileDescriptionCache()
public static void clearFileDescriptionCache(@NotNull String absolutePath)
absolutePath - path to clear file description cachepublic static FileDescription getFileDescription(@NotNull File file, @Nullable String fileSize)
file - file to processfileSize - file size on disk@NotNull public static String appropriateFileName(@NotNull String text)
text - text to trim@NotNull public static String appropriateFileName(@NotNull String text, @NotNull String replacement)
text - text to trimreplacement - replacement for each invalid symbolpublic static void clearDisplayFileNameCache()
public static void clearDisplayFileNameCache(@NotNull String absolutePath)
absolutePath - path path path to clear file display name cache for@NotNull public static String getDisplayFileName(@NotNull File file)
file - file to processpublic static void clearDisplayFileCreationDateCache()
public static void clearDisplayFileCreationDateCache(@NotNull String absolutePath)
absolutePath - path path to clear file creation date cache for@NotNull public static String getDisplayFileCreationDate(@NotNull File file)
file - file to processpublic static void clearDisplayFileModificationDateCache()
public static void clearDisplayFileModificationDateCache(@NotNull String absolutePath)
absolutePath - path path to clear file modification date cache for@NotNull public static String getDisplayFileModificationDate(@NotNull File file)
file - file to processpublic static void clearFileTypeDescriptionCache()
public static void clearFileTypeDescriptionCache(@NotNull String absolutePath)
absolutePath - path to clear file type description cache for@NotNull public static String getFileTypeDescription(@Nullable File file)
file - file to process@Nullable public static Icon getFileIcon(@Nullable File file)
file - file to process@Nullable public static Icon getFileIcon(@Nullable File file, boolean large)
file - file to processlarge - whether return large icon or not@Nullable public static Icon getStandardFileIcon(@Nullable File file, boolean large)
file - file to processlarge - whether return large icon or not@Nullable public static Icon getStandardFileIcon(@Nullable File file, boolean large, boolean enabled)
file - file to processlarge - whether return large icon or notenabled - whether enabled icon or not@Nullable public static Icon getStandardFileIcon(boolean large, @NotNull String extension, float opacity)
large - whether return large icon or notextension - file extensionopacity - icon opacity@Nullable public static Icon getIconResource(@NotNull Class nearClass, @NotNull String resource)
nearClass - class near which the icon is locatedresource - icon location@Nullable public static Icon getIconResource(@NotNull Class nearClass, @NotNull String resource, float opacity)
nearClass - class near which the icon is locatedresource - icon locationopacity - custom icon opacity@NotNull public static WebTimer trackFile(@NotNull File file, @NotNull SystemFileListener listener)
file - file to tracklistener - system file listenerCopyright © 2020. All rights reserved.