public final class FileUtil
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
concat(java.lang.String dir,
java.lang.String file) |
static boolean |
copy(java.io.File src,
java.io.File dest,
CopyProgressListener l)
This is the same as calling
copy(File, File, CopyProgressListener, boolean) with
overwrite param as true |
static boolean |
copy(java.io.File src,
java.io.File dest,
CopyProgressListener l,
boolean overwrite) |
static void |
copy(java.io.File src,
java.net.URL dest,
CopyProgressListener listener,
TimeoutConstraint timeoutConstraint) |
static void |
copy(java.io.InputStream src,
java.io.File dest,
CopyProgressListener l) |
static void |
copy(java.io.InputStream src,
java.io.OutputStream dest,
CopyProgressListener l) |
static void |
copy(java.io.InputStream src,
java.io.OutputStream dest,
CopyProgressListener l,
boolean autoClose) |
static void |
copy(java.net.URL src,
java.io.File dest,
CopyProgressListener listener,
TimeoutConstraint timeoutConstraint) |
static boolean |
deepCopy(java.io.File src,
java.io.File dest,
CopyProgressListener l,
boolean overwrite) |
static boolean |
forceDelete(java.io.File file)
Recursively delete file
|
static long |
getFileLength(java.io.File file)
Get the length of the file, or the sum of the children lengths if it is a directory
|
static java.util.List<java.io.File> |
getPathFiles(java.io.File root,
java.io.File file)
Returns a list of Files composed of all directories being parent of file and child of root +
file and root themselves.
|
static boolean |
isLeadingPath(java.io.File leading,
java.io.File path)
Learn whether one path "leads" another.
|
static boolean |
isLeadingPath(java.io.File leading,
java.io.File path,
boolean resolveSymlinks)
Learn whether one path "leads" another.
|
static java.util.Collection<java.io.File> |
listAll(java.io.File dir,
java.util.Collection<java.lang.String> ignore) |
static java.io.File |
normalize(java.lang.String path)
"Normalize" the given absolute path.
|
static boolean |
prepareCopy(java.io.File src,
java.io.File dest,
boolean overwrite) |
static java.lang.String |
readEntirely(java.io.BufferedReader in)
Reads the whole BufferedReader line by line, using \n as line separator for each line.
|
static java.lang.String |
readEntirely(java.io.File f)
Reads the entire content of the file and returns it as a String.
|
static java.lang.String |
readEntirely(java.io.InputStream is)
Reads the entire content of the
InputStream and returns it as a String. |
static java.io.File |
resolveFile(java.io.File file,
java.lang.String filename) |
static boolean |
symlink(java.io.File target,
java.io.File link,
boolean overwrite)
Creates a symbolic link at
link whose target will be the target. |
static java.io.InputStream |
unwrapPack200(java.io.InputStream packed) |
public static boolean symlink(java.io.File target,
java.io.File link,
boolean overwrite)
throws java.io.IOException
link whose target will be the target. Depending
on the underlying filesystem, this method may not always be able to create a symbolic link,
in which case this method returns false.target - The File which will be the target of the symlink being createdlink - The path to the symlink that needs to be createdoverwrite - true if any existing file at link has to be overwritten.
False otherwisejava.io.IOException - if Files.createSymbolicLink(java.nio.file.Path, java.nio.file.Path, java.nio.file.attribute.FileAttribute<?>...) failspublic static boolean copy(java.io.File src,
java.io.File dest,
CopyProgressListener l)
throws java.io.IOException
copy(File, File, CopyProgressListener, boolean) with
overwrite param as truesrc - The source to copydest - The destinationl - A CopyProgressListener. Can be nulljava.io.IOException - If any exception occurs during the copy operationpublic static boolean prepareCopy(java.io.File src,
java.io.File dest,
boolean overwrite)
throws java.io.IOException
java.io.IOExceptionpublic static boolean copy(java.io.File src,
java.io.File dest,
CopyProgressListener l,
boolean overwrite)
throws java.io.IOException
java.io.IOExceptionpublic static boolean deepCopy(java.io.File src,
java.io.File dest,
CopyProgressListener l,
boolean overwrite)
throws java.io.IOException
java.io.IOExceptionpublic static void copy(java.net.URL src,
java.io.File dest,
CopyProgressListener listener,
TimeoutConstraint timeoutConstraint)
throws java.io.IOException
java.io.IOExceptionpublic static void copy(java.io.File src,
java.net.URL dest,
CopyProgressListener listener,
TimeoutConstraint timeoutConstraint)
throws java.io.IOException
java.io.IOExceptionpublic static void copy(java.io.InputStream src,
java.io.File dest,
CopyProgressListener l)
throws java.io.IOException
java.io.IOExceptionpublic static void copy(java.io.InputStream src,
java.io.OutputStream dest,
CopyProgressListener l)
throws java.io.IOException
java.io.IOExceptionpublic static void copy(java.io.InputStream src,
java.io.OutputStream dest,
CopyProgressListener l,
boolean autoClose)
throws java.io.IOException
java.io.IOExceptionpublic static java.lang.String readEntirely(java.io.BufferedReader in)
throws java.io.IOException
Note that this method will add a final \n to the last line even though there is no new line character at the end of last line in the original reader.
The BufferedReader is closed when this method returns.
in - the BufferedReader to read fromBufferedReaderjava.io.IOException - if an IO problems occur during readingpublic static java.lang.String readEntirely(java.io.File f)
throws java.io.IOException
f - the file to read fromjava.io.IOException - if an IO problems occurs during readingpublic static java.lang.String readEntirely(java.io.InputStream is)
throws java.io.IOException
InputStream and returns it as a String.
The input stream is closed when this method returns.
is - the InputStream to read fromjava.io.IOException - if an IO problems occurs during readingpublic static java.lang.String concat(java.lang.String dir,
java.lang.String file)
public static boolean forceDelete(java.io.File file)
file - the file to deletepublic static java.util.List<java.io.File> getPathFiles(java.io.File root,
java.io.File file)
getPathFiles(new File("test"), new
File("test/dir1/dir2/file.txt")) => {new File("test/dir1"), new File("test/dir1/dir2"),
new File("test/dir1/dir2/file.txt") } Note that if root is not an ancestor of file, or
if root is null, all directories from the file system root will be returned.root - Filefile - Filepublic static java.util.Collection<java.io.File> listAll(java.io.File dir,
java.util.Collection<java.lang.String> ignore)
dir - The directory from which all files, including files in subdirectory) are
extracted.ignore - a Collection of filenames which must be excluded from listingpublic static java.io.File resolveFile(java.io.File file,
java.lang.String filename)
public static java.io.File normalize(java.lang.String path)
This includes:
File.getCanonicalPath() this method specifically does not resolve symbolic
links.path - the path to be normalized.java.lang.NullPointerException - if path is null.public static boolean isLeadingPath(java.io.File leading,
java.io.File path)
This method uses normalize(java.lang.String) under the covers and
does not resolve symbolic links.
If either path tries to go beyond the file system root (i.e. it contains more ".." segments than can be travelled up) the method will return false.
leading - The leading path, must not be null, must be absolute.path - The path to check, must not be null, must be absolute.public static boolean isLeadingPath(java.io.File leading,
java.io.File path,
boolean resolveSymlinks)
throws java.io.IOException
leading - The leading path, must not be null, must be absolute.path - The path to check, must not be null, must be absolute.resolveSymlinks - whether symbolic links shall be resolved
prior to comparing the paths.java.io.IOException - if resolveSymlinks is true and invoking
getCanonicaPath on either argument throws an exceptionpublic static long getFileLength(java.io.File file)
file - Filepublic static java.io.InputStream unwrapPack200(java.io.InputStream packed)
throws java.io.IOException
java.io.IOExceptionCopyright ©2007-2022 The Apache Software Foundation, Licensed under Apache License, Version 2.0.