public final class FileUtil extends Object
| Modifier and Type | Field and Description |
|---|---|
static FilenameFilter |
IMAGE_FILENAME_FILTER |
static char |
UNIX_FILE_SEPARATOR
The file path separator for UNIX based systems.
|
static Charset |
UTF8 |
static FilenameFilter |
VIDEO_FILENAME_FILTER |
static char |
WINDOWS_FILE_SEPARATOR
The file path separator for Windows based systems.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
closeSilent(AutoCloseable... closeables)
Close the writer without throwing an I/O exception if the close failed.
|
static void |
closeSilent(Collection<? extends AutoCloseable> closeables)
Close the writer without throwing an I/O exception if the close failed.
|
static String |
convertPath(String path)
Convert the path containing UNIX or Windows file separators to the local
File.separator character. |
static void |
copy(File src,
File dest) |
static long |
copy(File file,
OutputStream out)
Copy the contents of the file to the output stream.
|
static long |
copy(File file,
Writer out)
Copy the contents of the file to the writer.
|
static long |
copy(InputStream in,
File file)
Copy the contents of the input stream to the file.
|
static void |
copy(InputStream zin,
File file,
long sz)
Writes the content of a zip entry to a file using NIO.
|
static long |
copy(InputStream in,
OutputStream out)
Copy the contents of the input stream to the output stream.
|
static void |
copy(Reader in,
File file)
Copy the contents of the reader to the file.
|
static long |
copy(Reader in,
Writer out)
Copy the contents of the reader to the writer.
|
static void |
copy(String text,
File file) |
static File |
createTempDirectory(String prefix,
String suffix)
Create a new temporary directory.
|
static File |
createTempFile(String prefix,
String suffix) |
static InputStreamReader |
createUtf8Reader(InputStream in) |
static OutputStreamWriter |
createUtf8Writer(OutputStream out) |
static boolean |
deleteDirectory(File directory)
Delete a directory and all the files and sub directories below the
directory.
|
static boolean |
deleteDirectory(File directory,
boolean deleteRoot)
Delete all the files and sub directories below the directory.
|
static void |
deleteDirectory(File directory,
FilenameFilter filter) |
static void |
deleteFileOnExit(File file)
Add the file to be deleted on exit.
|
static void |
deleteFiles(File directory,
String pattern)
Delete the files that match the java regular expression.
|
static void |
deleteFilesOlderThan(File directory,
Date date) |
static void |
deleteFilesOlderThan(File directory,
long age) |
static String |
fromSafeName(String fileName) |
static String |
getBaseName(File file) |
static String |
getBaseName(String name) |
static String |
getCanonicalPath(File file) |
static String |
getCanonicalPath(String fileName) |
static File |
getCurrentDirectory() |
static List<File> |
getDirectories(File directory) |
static File |
getDirectory(File parent,
String path) |
static File |
getDirectory(String path) |
static List<String> |
getDirectoryNames(File directory) |
static File |
getFile(File file) |
static File |
getFile(File file,
String path) |
static File |
getFile(org.springframework.core.io.Resource resource) |
static File |
getFile(String path) |
static File |
getFile(URI uri) |
static File |
getFile(URL url) |
static String |
getFileAsString(String fileName) |
static List<String> |
getFileBaseNamesByExtension(File directory,
String extension) |
static String |
getFileName(File file) |
static String |
getFileName(String fileName) |
static String |
getFileNameExtension(File file) |
static String |
getFileNameExtension(String fileName) |
static List<String> |
getFileNameExtensions(File file) |
static List<String> |
getFileNameExtensions(String fileName) |
static String |
getFileNamePrefix(File file) |
static List<String> |
getFileNames(File directory,
FilenameFilter filter) |
static List<String> |
getFileNamesByExtension(File directory,
String extension) |
static List<File> |
getFiles(File directory,
FilenameFilter filter) |
static List<File> |
getFilesByExtension(File directory,
String... extensions) |
static File |
getFileWithExtension(File file,
String extension)
Get a new file object with the current extension replaced with the new extension.
|
static FileInputStream |
getInputStream(File file) |
static FileReader |
getReader(File file) |
static String |
getRelativePath(File parentDirectory,
File file)
Return the relative path of the file from the parentDirectory.
|
static File |
getSafeFileName(File directory,
String name) |
static String |
getSafeFileName(String name) |
static String |
getString(File file) |
static String |
getString(InputStream in) |
static String |
getString(Reader reader) |
static File |
getUrlFile(String url) |
static File |
getUserHomeDirectory() |
static Writer |
getWriter(File file) |
static boolean |
isRoot(File file) |
static List<File> |
listVisibleFiles(File file) |
static List<File> |
listVisibleFiles(File file,
FileFilter filter) |
static String |
toSafeName(String host) |
static URL |
toUrl(File file) |
static String |
toUrlString(File file) |
public static final char UNIX_FILE_SEPARATOR
public static final Charset UTF8
public static final char WINDOWS_FILE_SEPARATOR
public static final FilenameFilter IMAGE_FILENAME_FILTER
public static final FilenameFilter VIDEO_FILENAME_FILTER
public static void closeSilent(AutoCloseable... closeables)
closeables - The closables to close.public static void closeSilent(Collection<? extends AutoCloseable> closeables)
closeables - The closables to close.public static String convertPath(String path)
File.separator character.path - The path to convert.public static long copy(File file, OutputStream out) throws IOException
file - The file to read the contents from.out - The output stream to write the contents to.IOException - If an I/O error occurs.public static long copy(File file, Writer out) throws IOException
file - The file to read the contents from.out - The writer to write the contents to.IOException - If an I/O error occurs.public static long copy(InputStream in, File file)
in - The input stream to read the contents from.file - The file to write the contents to.IOException - If an I/O error occurs.public static void copy(InputStream zin, File file, long sz) throws IOException
zin - input stream from zip filefile - file path where this entry will be savedsz - file sizeIOException - if an i/o errorpublic static long copy(InputStream in, OutputStream out)
in - The input stream to read the contents from.out - The output stream to write the contents to.public static void copy(Reader in, File file)
in - The reader to read the contents from.file - The file to write the contents to.IOException - If an I/O error occurs.public static long copy(Reader in, Writer out)
in - The reader to read the contents from.out - The writer to write the contents to.IOException - If an I/O error occurs.public static File createTempDirectory(String prefix, String suffix)
prefix - The file name prefix.suffix - The file name suffix.IOException - If there was an exception creating the directory.public static InputStreamReader createUtf8Reader(InputStream in)
public static OutputStreamWriter createUtf8Writer(OutputStream out)
public static boolean deleteDirectory(File directory)
directory - The directory to delete.public static boolean deleteDirectory(File directory, boolean deleteRoot)
directory - The directory to delete.deleteRoot - Flag indicating if the directory should also be deleted.IOException - If a file or directory could not be deleted.public static void deleteDirectory(File directory, FilenameFilter filter)
public static void deleteFileOnExit(File file)
file - The file or directory to delete.public static void deleteFiles(File directory, String pattern)
directory - The directory.pattern - The regular expression to matchpublic static void deleteFilesOlderThan(File directory, long age)
public static File getCurrentDirectory()
public static File getFile(org.springframework.core.io.Resource resource) throws IOException
IOExceptionpublic static List<String> getFileBaseNamesByExtension(File directory, String extension)
public static List<String> getFileNames(File directory, FilenameFilter filter)
public static List<String> getFileNamesByExtension(File directory, String extension)
public static List<File> getFiles(File directory, FilenameFilter filter)
public static List<File> getFilesByExtension(File directory, String... extensions)
public static File getFileWithExtension(File file, String extension)
file - extension - public static FileInputStream getInputStream(File file)
public static FileReader getReader(File file)
public static String getRelativePath(File parentDirectory, File file)
parentDirectory - The parent directory.file - The file to return the relative path for.IOException - If an I/O error occurs.public static String getString(InputStream in)
public static File getUserHomeDirectory()
public static boolean isRoot(File file)
public static List<File> listVisibleFiles(File file, FileFilter filter)
Copyright © 2015 Revolution Systems Inc.. All rights reserved.