public class Files extends Object
| Modifier and Type | Method and Description |
|---|---|
static String |
basePath(String path,
String extension)
Strips off the given extension (probably returned from Files.extension()) from the path,
yielding a base pathname.
|
static String |
cleanupFilename(String filename)
Replaces commonly unsupported characters with '_'
|
static void |
copy(File sourceFile,
File targetFile)
make a copy of a file
|
static String |
extension(String path)
Gets extension from path
|
static String |
filename(String path)
Gets filename from path
|
static Time |
getLastModified(File file)
get last modification timestamp for file
|
static File |
getLocalFileFromUrl(String url)
for urls that point to local files (e.g.
|
static File |
getLocalFileFromUrl(URL url)
for urls that point to local files (e.g.
|
static boolean |
mkdirs(File folder)
Utility method for creating a directory.
|
static byte[] |
readBytes(File file)
read binary file fully
|
static boolean |
remove(File file)
Deletes a normal file.
|
static boolean |
removeAsync(File file,
IFileCleaner fileCleaner)
Schedules a file for removal asynchronously.
|
static boolean |
removeFolder(File folder)
Deletes a folder by recursively removing the files and folders inside it.
|
static boolean |
removeFolderAsync(File folder,
IFileCleaner fileCleaner)
Schedules a folder and all files inside it for asynchronous removal.
|
static int |
writeTo(File file,
InputStream input)
Writes the given input stream to the given file
|
static int |
writeTo(File file,
InputStream input,
int bufSize)
Writes the given input stream to the given file
|
public static String basePath(String path, String extension)
path - The path, possibly with an extension to stripextension - The extension to strip, or null if no extension existspublic static String extension(String path)
path - The pathpublic static String filename(String path)
path - The pathpublic static boolean remove(File file)
If the file cannot be deleted for any reason then at most 50 retries are attempted with delay of 100ms at each 10th attempt.
file - the file to deletetrue if file was deleted, false if the file don't exist, is a folder
or cannot be removed for some reasonpublic static boolean removeFolder(File folder)
remove(File) for plain files.folder - the folder to deletetrue if the folder is deleted successfully.public static boolean removeAsync(File file, IFileCleaner fileCleaner)
file - the file to be removedfileCleaner - the file cleaner that will be used to remove the filefalse if the file is null or a folder, true -
otherwise (i.e. if it is scheduled)public static boolean removeFolderAsync(File folder, IFileCleaner fileCleaner)
folder - the folder to be removedfileCleaner - the file cleaner that will be used to remove the filefalse if the folder is null or a normal file, true -
otherwise (i.e. if it is scheduled)public static int writeTo(File file, InputStream input) throws IOException
file - The file to write toinput - The inputIOExceptionpublic static byte[] readBytes(File file) throws IOException
file - file to readIOException - is something went wrongpublic static int writeTo(File file, InputStream input, int bufSize) throws IOException
file - The file to write toinput - The inputbufSize - The memory buffer size. 4096 is a good value.IOExceptionpublic static String cleanupFilename(String filename)
Replaces commonly unsupported characters with '_'
filename - to be cleanedpublic static void copy(File sourceFile, File targetFile) throws IOException
sourceFile - source file that needs to be clonedtargetFile - target file that should be a duplicate of source fileIOException - if something went wrongpublic static File getLocalFileFromUrl(URL url)
url - url of the resourcenull otherwisegetLocalFileFromUrl(String)public static File getLocalFileFromUrl(String url)
url - url of the resourcenull otherwisegetLocalFileFromUrl(URL)public static Time getLastModified(File file)
file - public static boolean mkdirs(File folder)
folder - the folder to createtrue if the creation is successful, false - otherwiseCopyright © 2006–2021 Apache Software Foundation. All rights reserved.