public final class FileUtils extends Object
Modifier and Type | Method and Description |
---|---|
static void |
append(File src,
File dst) |
static void |
append(File src,
File dst,
boolean appendNewLine) |
static void |
append(InputStream in,
File file) |
static void |
append(InputStream in,
File file,
boolean appendNewLine) |
static boolean |
areFilesContentEquals(String expected,
String source)
Compares two files content as String even if their EOL are different
|
static void |
close(InputStream in) |
static void |
close(OutputStream out) |
static void |
collectFiles(File root,
FileNamePattern pattern,
List<File> result) |
static void |
collectFiles(File root,
List<File> result) |
static void |
copy(File[] src,
File dst) |
static void |
copy(File src,
File dst)
Copies source to destination.
|
static void |
copy(InputStream in,
OutputStream out) |
static void |
copyFile(File src,
File dst) |
static void |
copyToFile(InputStream in,
File file) |
static void |
copyTree(File src,
File dst)
Copies recursively source to destination.
|
static void |
copyTree(File src,
File dst,
PathFilter filter) |
static void |
copyTree(File src,
File dst,
Path prefix,
PathFilter filter) |
protected static void |
copyTree(int rootIndex,
File src,
File dst,
Path prefix,
PathFilter filter) |
static void |
deleteTree(File dir)
Deprecated.
Since 5.6. Use
FileUtils.deleteDirectory(File) or
FileUtils.deleteQuietly(File) instead. |
static void |
download(URL url,
File file) |
static void |
emptyDirectory(File dir)
Deprecated.
Since 5.6. Use
FileUtils.deleteDirectory(File) or
FileUtils.deleteQuietly(File) instead. Warning: suggested methods will
delete the root directory whereas current method doesn't. |
static File[] |
findFiles(File root,
String pattern,
boolean recurse) |
static String |
getFileExtension(String path) |
static File |
getFileFromURL(URL url) |
static String |
getFileName(String path) |
static String |
getFileNameNoExt(String path) |
static String |
getFilePathFromUrl(URL url)
Decodes an URL path so that is can be processed as a filename later.
|
static String |
getParentPath(String path) |
static File |
getResourceFileFromContext(String resource) |
static String |
getResourcePathFromContext(String resource)
Retrieves the total path of a resource from the Thread Context.
|
static String |
read(InputStream in)
Deprecated.
Since 5.7. Use
IOUtils.toString(InputStream, java.nio.charset.Charset) explicitly instead (or
any other encoding when provided by the source of the byte stream). |
static byte[] |
readBytes(File file) |
static byte[] |
readBytes(InputStream in) |
static byte[] |
readBytes(URL url) |
static String |
readFile(File file) |
static List<String> |
readLines(File file) |
static List<String> |
readLines(InputStream in) |
static void |
safeClose(Closeable stream) |
static File |
urlToFile(String url)
Create a file handler (this doesn't create a real file) given a file URI.
|
static File |
urlToFile(URL url) |
static void |
writeFile(File file,
byte[] buf) |
static void |
writeFile(File file,
byte[] buf,
boolean append) |
static void |
writeFile(File file,
String buf) |
static void |
writeFile(File file,
String buf,
boolean append) |
static void |
writeLines(File file,
List<String> lines) |
public static void copy(InputStream in, OutputStream out) throws IOException
IOException
@Deprecated public static String read(InputStream in) throws IOException
IOUtils.toString(InputStream, java.nio.charset.Charset)
explicitly instead (or
any other encoding when provided by the source of the byte stream).IOException
public static byte[] readBytes(URL url) throws IOException
IOException
public static byte[] readBytes(InputStream in) throws IOException
IOException
public static String readFile(File file) throws IOException
IOException
public static List<String> readLines(File file) throws IOException
IOException
public static void writeLines(File file, List<String> lines) throws IOException
IOException
public static byte[] readBytes(File file) throws IOException
IOException
public static void writeFile(File file, byte[] buf) throws IOException
IOException
public static void writeFile(File file, byte[] buf, boolean append) throws IOException
file
- buf
- append
- IOException
public static void writeFile(File file, String buf) throws IOException
IOException
public static void writeFile(File file, String buf, boolean append) throws IOException
file
- buf
- append
- IOException
public static void download(URL url, File file) throws IOException
IOException
@Deprecated public static void deleteTree(File dir)
FileUtils.deleteDirectory(File)
or
FileUtils.deleteQuietly(File)
instead.@Deprecated public static void emptyDirectory(File dir)
FileUtils.deleteDirectory(File)
or
FileUtils.deleteQuietly(File)
instead. Warning: suggested methods will
delete the root directory whereas current method doesn't.public static void copyToFile(InputStream in, File file) throws IOException
IOException
public static void append(File src, File dst) throws IOException
IOException
public static void append(File src, File dst, boolean appendNewLine) throws IOException
IOException
public static void append(InputStream in, File file) throws IOException
IOException
public static void append(InputStream in, File file, boolean appendNewLine) throws IOException
IOException
public static void copy(File src, File dst) throws IOException
src
- the source file or directorydst
- the destination file or directoryIOException
public static void copy(File[] src, File dst) throws IOException
IOException
public static void copyFile(File src, File dst) throws IOException
IOException
public static void copyTree(File src, File dst) throws IOException
The source file is assumed to be a directory.
src
- the source directorydst
- the destination directoryIOException
public static void copyTree(File src, File dst, PathFilter filter) throws IOException
IOException
public static void copyTree(File src, File dst, Path prefix, PathFilter filter) throws IOException
IOException
protected static void copyTree(int rootIndex, File src, File dst, Path prefix, PathFilter filter) throws IOException
IOException
public static String getFilePathFromUrl(URL url)
url
- the Url to be processed.public static File getFileFromURL(URL url)
public static String getParentPath(String path)
public static String getFileName(String path)
public static String getFileExtension(String path)
public static String getFileNameNoExt(String path)
public static String getResourcePathFromContext(String resource)
resource
- the resource name to be retrieved.public static File getResourceFileFromContext(String resource)
public static void collectFiles(File root, FileNamePattern pattern, List<File> result)
public static void collectFiles(File root, List<File> result)
public static void close(InputStream in)
public static void close(OutputStream out)
public static File urlToFile(String url) throws MalformedURLException
MalformedURLException
public static List<String> readLines(InputStream in) throws IOException
IOException
public static boolean areFilesContentEquals(String expected, String source)
expected
- a file content with Windows or Unix like EOLsource
- another file content with Windows or Unix like EOLCopyright © 2015 Nuxeo SA. All rights reserved.