public final class IOUtil extends Object
Note: This class includes codes copied from Apache Commons Lang, Apache Commons IO, Google Guava and other open source projects under the Apache License 2.0. The methods copied from other libraries/frameworks/projects may be modified in this class.
| Modifier and Type | Method and Description |
|---|---|
static void |
append(File output,
byte[] bytes) |
static void |
append(File output,
byte[] bytes,
int offset,
int len) |
static void |
append(File output,
char[] chars) |
static void |
append(File output,
char[] chars,
Charset charset) |
static void |
append(File output,
char[] chars,
int offset,
int len) |
static void |
append(File output,
char[] chars,
int offset,
int len,
Charset charset) |
static void |
append(File output,
CharSequence str) |
static void |
append(File output,
CharSequence str,
Charset charset) |
static long |
append(File output,
File input) |
static long |
append(File output,
File input,
long offset,
long len) |
static long |
append(File output,
InputStream input) |
static long |
append(File output,
InputStream input,
long offset,
long len) |
static long |
append(File output,
Reader input) |
static long |
append(File output,
Reader input,
Charset charset) |
static long |
append(File output,
Reader input,
long offset,
long len) |
static long |
append(File output,
Reader input,
long offset,
long len,
Charset charset) |
static void |
appendLine(File output,
CharSequence str) |
static void |
appendLine(File output,
CharSequence str,
Charset charset) |
static char[] |
bytes2Chars(byte[] bytes)
Bytes 2 chars.
|
static char[] |
bytes2Chars(byte[] bytes,
Charset charset)
Bytes 2 chars.
|
static char[] |
bytes2Chars(byte[] bytes,
int offset,
int len,
Charset charset)
Bytes 2 chars.
|
static byte[] |
chars2Bytes(char[] chars)
Chars 2 bytes.
|
static byte[] |
chars2Bytes(char[] chars,
Charset charset)
Chars 2 bytes.
|
static byte[] |
chars2Bytes(char[] chars,
int offset,
int len,
Charset charset)
Chars 2 bytes.
|
static boolean |
cleanDirectory(File directory)
Cleans a directory without deleting it.
|
static void |
close(AutoCloseable closeable) |
static void |
closeAll(AutoCloseable... a) |
static void |
closeAll(Collection<? extends AutoCloseable> c) |
static void |
closeAllQuietly(AutoCloseable... a)
Close all quietly.
|
static void |
closeAllQuietly(Collection<? extends AutoCloseable> c)
Close all quietly.
|
static void |
closeQuietly(AutoCloseable closeable) |
static long |
copy(InputStream in,
Path target,
CopyOption... options) |
static long |
copy(Path source,
OutputStream output) |
static Path |
copy(Path source,
Path target,
CopyOption... options) |
static void |
copyFileToDirectory(File srcFile,
File destDir) |
static void |
copyFileToDirectory(File srcFile,
File destDir,
boolean preserveFileDate) |
static <E extends Exception> |
copyFileToDirectory(File srcFile,
File destDir,
boolean preserveFileDate,
Throwables.BiPredicate<? super File,? super File,E> filter)
Copy the specified
scrFile if it's a file or its sub files/directories if it's a directory to the target destDir with the specified filter. |
static void |
copyURLToFile(URL source,
File destination)
Copies bytes from the URL
source to a file
destination. |
static void |
copyURLToFile(URL source,
File destination,
int connectionTimeout,
int readTimeout)
Copies bytes from the URL
source to a file
destination. |
static boolean |
createIfNotExists(File file)
Creates the if not exists.
|
static boolean |
deleteAllIfExists(File file)
Delete the specified file and all its sub files/directories if it's a directory.
|
static boolean |
deleteFiles(File dir) |
static <E extends Exception> |
deleteFiles(File dir,
Throwables.BiPredicate<? super File,? super File,E> filter)
Delete the specified
dir if it's a file or its sub files/directories if it's a directory with the specified filter. |
static boolean |
deleteIfExists(File file)
Delete the specified file (or directory).
|
static String |
getFileExtension(String fullName)
Note: copied from Google Guava under Apache License v2.
|
static String |
getNameWithoutExtension(String file)
Note: copied from Google Guava under Apache License v2.
|
static boolean |
isFileNewer(File file,
Date date)
Tests if the specified
File is newer than the specified Date. |
static boolean |
isFileNewer(File file,
File reference)
Tests if the specified
File is newer than the reference File. |
static boolean |
isFileOlder(File file,
Date date)
Tests if the specified
File is older than the specified Date. |
static boolean |
isFileOlder(File file,
File reference)
Tests if the specified
File is older than the reference File. |
static boolean |
isSymbolicLink(File file)
Determines whether the specified file is a Symbolic Link rather than an actual file.
|
static List<String> |
list(File parentPath) |
static List<String> |
list(File parentPath,
boolean recursively,
boolean excludeDirectory) |
static <E extends Exception> |
list(File parentPath,
boolean recursively,
Throwables.BiPredicate<? super File,? super File,E> filter) |
static List<File> |
listDirectories(File parentPath) |
static List<File> |
listDirectories(File parentPath,
boolean recursively) |
static List<File> |
listFiles(File parentPath) |
static List<File> |
listFiles(File parentPath,
boolean recursively,
boolean excludeDirectory) |
static <E extends Exception> |
listFiles(File parentPath,
boolean recursively,
Throwables.BiPredicate<? super File,? super File,E> filter) |
static MappedByteBuffer |
map(File file)
Note: copied from Google Guava under Apache License v2.
|
static MappedByteBuffer |
map(File file,
FileChannel.MapMode mode)
Note: copied from Google Guava under Apache License v2.
|
static MappedByteBuffer |
map(File file,
FileChannel.MapMode mode,
long offset,
long len)
Note: copied from Google Guava under Apache License v2.
|
static long |
merge(Collection<File> sourceFiles,
File destFile)
Merge the specified source files into the destination file.
|
static long |
merge(File[] sourceFiles,
File destFile) |
static boolean |
mkdirIfNotExists(File dir) |
static boolean |
mkdirsIfNotExists(File dir) |
static void |
move(File srcFile,
File destDir) |
static BufferedReader |
newBufferedReader(File file)
New buffered reader.
|
static BufferedReader |
newBufferedReader(File file,
Charset charset)
New buffered reader.
|
static BufferedReader |
newBufferedReader(InputStream is)
New buffered reader.
|
static BufferedReader |
newBufferedReader(InputStream is,
Charset charset)
New buffered reader.
|
static BufferedReader |
newBufferedReader(Path path)
New buffered reader.
|
static BufferedReader |
newBufferedReader(Path path,
Charset charset)
New buffered reader.
|
static BufferedWriter |
newBufferedWriter(File file)
New buffered writer.
|
static BufferedWriter |
newBufferedWriter(File file,
Charset charset)
New buffered writer.
|
static BufferedWriter |
newBufferedWriter(OutputStream os)
New buffered writer.
|
static BufferedWriter |
newBufferedWriter(OutputStream os,
Charset charset)
New buffered writer.
|
static GZIPInputStream |
newGZIPInputStream(InputStream is)
New GZIP input stream.
|
static GZIPInputStream |
newGZIPInputStream(InputStream is,
int bufferSize)
Creates a new input stream with the specified buffer size.
|
static GZIPOutputStream |
newGZIPOutputStream(OutputStream os)
New GZIP output stream.
|
static GZIPOutputStream |
newGZIPOutputStream(OutputStream os,
int bufferSize)
Creates a new input stream with the specified buffer size.
|
static LZ4BlockInputStream |
newLZ4BlockInputStream(InputStream is)
New LZ 4 block input stream.
|
static LZ4BlockOutputStream |
newLZ4BlockOutputStream(OutputStream os)
New LZ 4 block output stream.
|
static LZ4BlockOutputStream |
newLZ4BlockOutputStream(OutputStream os,
int blockSize)
Creates a new input stream with the specified buffer size.
|
static SnappyInputStream |
newSnappyInputStream(InputStream is)
New snappy input stream.
|
static SnappyOutputStream |
newSnappyOutputStream(OutputStream os)
New snappy output stream.
|
static SnappyOutputStream |
newSnappyOutputStream(OutputStream os,
int bufferSize)
Creates a new input stream with the specified buffer size.
|
static int |
read(File file,
byte[] buf) |
static int |
read(File file,
byte[] buf,
int off,
int len) |
static int |
read(File file,
char[] buf) |
static int |
read(File file,
char[] buf,
Charset charset) |
static int |
read(File file,
char[] buf,
int off,
int len) |
static int |
read(File file,
char[] buf,
int off,
int len,
Charset charset) |
static int |
read(InputStream is,
byte[] buf) |
static int |
read(InputStream is,
byte[] buf,
int off,
int len) |
static int |
read(Reader reader,
char[] buf) |
static int |
read(Reader reader,
char[] buf,
int off,
int len) |
static byte[] |
readAllBytes(File file) |
static byte[] |
readAllBytes(InputStream is) |
static char[] |
readAllChars(File file) |
static char[] |
readAllChars(File file,
Charset encoding) |
static char[] |
readAllChars(InputStream is) |
static char[] |
readAllChars(InputStream is,
Charset encoding) |
static char[] |
readAllChars(Reader reader) |
static List<String> |
readAllLines(File file) |
static List<String> |
readAllLines(File file,
Charset encoding) |
static List<String> |
readAllLines(InputStream is) |
static List<String> |
readAllLines(InputStream is,
Charset encoding) |
static List<String> |
readAllLines(Reader reader) |
static byte[] |
readBytes(File file) |
static byte[] |
readBytes(File file,
long offset,
int maxLen) |
static byte[] |
readBytes(InputStream is) |
static byte[] |
readBytes(InputStream is,
long offset,
int maxLen) |
static char[] |
readChars(File file) |
static char[] |
readChars(File file,
Charset encoding) |
static char[] |
readChars(File file,
long offset,
int maxLen) |
static char[] |
readChars(File file,
long offset,
int maxLen,
Charset encoding) |
static char[] |
readChars(InputStream is) |
static char[] |
readChars(InputStream is,
Charset encoding) |
static char[] |
readChars(InputStream is,
long offset,
int maxLen) |
static char[] |
readChars(InputStream is,
long offset,
int maxLen,
Charset encoding) |
static char[] |
readChars(Reader reader) |
static char[] |
readChars(Reader reader,
long offset,
int maxLen) |
static String |
readLine(File file) |
static String |
readLine(File file,
int lineIndex) |
static String |
readLine(File file,
int lineIndex,
Charset encoding) |
static String |
readLine(InputStream is) |
static String |
readLine(InputStream is,
int lineIndex) |
static String |
readLine(InputStream is,
int lineIndex,
Charset encoding) |
static String |
readLine(Reader reader) |
static String |
readLine(Reader reader,
int lineIndex) |
static List<String> |
readLines(File file) |
static List<String> |
readLines(File file,
Charset encoding) |
static List<String> |
readLines(File file,
int offset,
int count) |
static List<String> |
readLines(File file,
int offset,
int count,
Charset encoding) |
static List<String> |
readLines(InputStream is) |
static List<String> |
readLines(InputStream is,
Charset encoding) |
static List<String> |
readLines(InputStream is,
int offset,
int count) |
static List<String> |
readLines(InputStream is,
int offset,
int count,
Charset encoding) |
static List<String> |
readLines(Reader reader) |
static List<String> |
readLines(Reader reader,
int offset,
int count) |
static String |
readString(File file)
Read all content into one
String. |
static String |
readString(File file,
Charset encoding)
Read all content into one
String. |
static String |
readString(File file,
long offset,
int maxLen) |
static String |
readString(File file,
long offset,
int maxLen,
Charset encoding) |
static String |
readString(InputStream is)
Read all content into one
String. |
static String |
readString(InputStream is,
Charset encoding)
Read all content into one
String. |
static String |
readString(InputStream is,
long offset,
int maxLen) |
static String |
readString(InputStream is,
long offset,
int maxLen,
Charset encoding) |
static String |
readString(Reader reader)
Read all content into one
String. |
static String |
readString(Reader reader,
long offset,
int maxLen) |
static boolean |
renameTo(File srcFile,
String newFileName) |
static String |
simplifyPath(String pathname)
Note: copied from Google Guava under Apache License v2.
|
static long |
sizeOf(File file)
Returns the size of the specified file or directory.
|
static long |
sizeOfDirectory(File directory)
Counts the size of a directory recursively (sum of the length of all files).
|
static long |
skip(InputStream input,
long toSkip)
Return the count of skipped bytes.
|
static long |
skip(Reader input,
long toSkip)
Return the count of skipped chars.
|
static void |
skipFully(InputStream input,
long toSkip) |
static void |
skipFully(Reader input,
long toSkip) |
static void |
split(File file,
int countOfParts) |
static void |
split(File file,
int countOfParts,
File destDir) |
static void |
splitBySize(File file,
long sizeOfPart)
Split by size.
|
static void |
splitBySize(File file,
long sizeOfPart,
File destDir)
Mostly it's designed for (zipped/unzipped/log) text files.
|
static InputStream |
string2InputStream(String str)
String 2 input stream.
|
static InputStream |
string2InputStream(String str,
Charset charset)
String 2 input stream.
|
static Reader |
string2Reader(String str)
String 2 reader.
|
static Writer |
stringBuilder2Writer(StringBuilder sb)
String builder 2 writer.
|
static File |
toFile(URL url)
Convert from a
URL to a File. |
static List<File> |
toFiles(Collection<URL> urls) |
static File[] |
toFiles(URL[] urls)
Converts each of an array of
URL to a File. |
static boolean |
touch(File file)
Update the last modified time of the file to system current time if the specified file exists.
|
static URL |
toURL(File file) |
static List<URL> |
toURLs(Collection<File> files)
To UR ls.
|
static URL[] |
toURLs(File[] files)
To UR ls.
|
static void |
unzip(File srcZipFile,
File targetDir) |
static void |
write(File output,
byte[] bytes) |
static void |
write(File output,
byte[] bytes,
int offset,
int len) |
static void |
write(File output,
char[] chars) |
static void |
write(File output,
char[] chars,
Charset charset) |
static void |
write(File output,
char[] chars,
int offset,
int len) |
static void |
write(File output,
char[] chars,
int offset,
int len,
Charset charset) |
static void |
write(File output,
CharSequence str) |
static void |
write(File output,
CharSequence str,
Charset charset) |
static long |
write(File output,
File input) |
static long |
write(File output,
File input,
long offset,
long len) |
static long |
write(File output,
InputStream input) |
static long |
write(File output,
InputStream input,
long offset,
long len) |
static long |
write(File output,
Reader input) |
static long |
write(File output,
Reader input,
Charset charset) |
static long |
write(File output,
Reader input,
long offset,
long len) |
static long |
write(File output,
Reader input,
long offset,
long len,
Charset charset) |
static void |
write(OutputStream output,
byte[] bytes) |
static void |
write(OutputStream output,
byte[] bytes,
boolean flush) |
static void |
write(OutputStream output,
byte[] bytes,
int offset,
int len) |
static void |
write(OutputStream output,
byte[] bytes,
int offset,
int len,
boolean flush) |
static void |
write(OutputStream output,
char[] chars) |
static void |
write(OutputStream output,
char[] chars,
boolean flush) |
static void |
write(OutputStream output,
char[] chars,
Charset charset) |
static void |
write(OutputStream output,
char[] chars,
int offset,
int len) |
static void |
write(OutputStream output,
char[] chars,
int offset,
int len,
boolean flush) |
static void |
write(OutputStream output,
char[] chars,
int offset,
int len,
Charset charset) |
static void |
write(OutputStream output,
char[] chars,
int offset,
int len,
Charset charset,
boolean flush) |
static void |
write(OutputStream output,
CharSequence str) |
static void |
write(OutputStream output,
CharSequence str,
boolean flush) |
static void |
write(OutputStream output,
CharSequence str,
Charset charset) |
static void |
write(OutputStream output,
CharSequence str,
Charset charset,
boolean flush) |
static long |
write(OutputStream output,
File input) |
static long |
write(OutputStream output,
File input,
boolean flush) |
static long |
write(OutputStream output,
File input,
long offset,
long len) |
static long |
write(OutputStream output,
File input,
long offset,
long len,
boolean flush) |
static long |
write(OutputStream output,
InputStream input) |
static long |
write(OutputStream output,
InputStream input,
boolean flush) |
static long |
write(OutputStream output,
InputStream input,
long offset,
long len) |
static long |
write(OutputStream output,
InputStream input,
long offset,
long len,
boolean flush) |
static void |
write(Writer writer,
boolean b) |
static void |
write(Writer writer,
boolean b,
boolean flush) |
static void |
write(Writer writer,
byte b) |
static void |
write(Writer writer,
byte b,
boolean flush) |
static void |
write(Writer writer,
char c) |
static void |
write(Writer output,
char[] chars) |
static void |
write(Writer output,
char[] chars,
boolean flush) |
static void |
write(Writer output,
char[] chars,
int offset,
int len) |
static void |
write(Writer output,
char[] chars,
int offset,
int len,
boolean flush) |
static void |
write(Writer writer,
char c,
boolean flush) |
static void |
write(Writer output,
CharSequence str) |
static void |
write(Writer output,
CharSequence str,
boolean flush) |
static void |
write(Writer writer,
double d) |
static void |
write(Writer writer,
double d,
boolean flush) |
static long |
write(Writer output,
File input) |
static long |
write(Writer output,
File input,
boolean flush) |
static long |
write(Writer output,
File input,
long offset,
long len) |
static long |
write(Writer output,
File input,
long offset,
long len,
boolean flush) |
static void |
write(Writer writer,
float f) |
static void |
write(Writer writer,
float f,
boolean flush) |
static void |
write(Writer writer,
int i) |
static void |
write(Writer writer,
int i,
boolean flush) |
static void |
write(Writer writer,
long lng) |
static void |
write(Writer writer,
long lng,
boolean flush) |
static long |
write(Writer output,
Reader input) |
static long |
write(Writer output,
Reader input,
boolean flush) |
static long |
write(Writer output,
Reader input,
long offset,
long len) |
static long |
write(Writer output,
Reader input,
long offset,
long len,
boolean flush) |
static void |
write(Writer writer,
short s) |
static void |
write(Writer writer,
short s,
boolean flush) |
static void |
writeLine(File file,
Object obj) |
static void |
writeLine(OutputStream os,
Object obj) |
static void |
writeLine(OutputStream os,
Object obj,
boolean flush) |
static void |
writeLine(Writer writer,
Object obj) |
static void |
writeLine(Writer writer,
Object obj,
boolean flush) |
static void |
writeLines(File file,
Collection<?> lines) |
static void |
writeLines(File file,
Collection<?> lines,
int offset,
int count) |
static void |
writeLines(File file,
Object[] lines) |
static void |
writeLines(File file,
Object[] lines,
int offset,
int count) |
static void |
writeLines(OutputStream os,
Collection<?> lines) |
static void |
writeLines(OutputStream os,
Collection<?> lines,
boolean flush) |
static void |
writeLines(OutputStream os,
Collection<?> lines,
int offset,
int count) |
static void |
writeLines(OutputStream os,
Collection<?> lines,
int offset,
int count,
boolean flush) |
static void |
writeLines(OutputStream os,
Object[] lines) |
static void |
writeLines(OutputStream os,
Object[] lines,
boolean flush) |
static void |
writeLines(OutputStream os,
Object[] lines,
int offset,
int count) |
static void |
writeLines(OutputStream os,
Object[] lines,
int offset,
int count,
boolean flush) |
static void |
writeLines(Writer writer,
Collection<?> lines) |
static void |
writeLines(Writer writer,
Collection<?> lines,
boolean flush) |
static void |
writeLines(Writer writer,
Collection<?> lines,
int offset,
int count) |
static void |
writeLines(Writer writer,
Collection<?> lines,
int offset,
int count,
boolean flush) |
static void |
writeLines(Writer writer,
Object[] lines) |
static void |
writeLines(Writer writer,
Object[] lines,
boolean flush) |
static void |
writeLines(Writer writer,
Object[] lines,
int offset,
int count) |
static void |
writeLines(Writer writer,
Object[] lines,
int offset,
int count,
boolean flush) |
static void |
zip(Collection<File> sourceFiles,
File targetFile) |
static void |
zip(File sourceFile,
File targetFile) |
public static final String HOST_NAME
public static final int CPU_CORES
public static final long ONE_KB
public static final long ONE_MB
public static final long ONE_GB
public static final long ONE_TB
public static final long ONE_PB
public static final long ONE_EB
public static final long ONE_ZB
public static final int MAX_MEMORY_IN_MB
public static final String OS_NAME
public static final String OS_VERSION
public static final String OS_ARCH
public static final boolean IS_OS_WINDOWS
public static final boolean IS_OS_MAC
public static final boolean IS_OS_MAC_OSX
public static final boolean IS_OS_LINUX
public static final boolean IS_PLATFORM_ANDROID
public static final String JAVA_HOME
public static final String JAVA_VERSION
public static final String JAVA_VENDOR
public static final String JAVA_CLASS_PATH
public static final String JAVA_CLASS_VERSION
public static final String JAVA_RUNTIME_NAME
public static final String JAVA_RUNTIME_VERSION
public static final String JAVA_SPECIFICATION_NAME
public static final String JAVA_SPECIFICATION_VENDOR
public static final String JAVA_SPECIFICATION_VERSION
public static final String JAVA_VM_INFO
public static final String JAVA_VM_NAME
public static final String JAVA_VM_SPECIFICATION_NAME
public static final String JAVA_VM_SPECIFICATION_VENDOR
public static final String JAVA_VM_SPECIFICATION_VERSION
public static final String JAVA_VM_VENDOR
public static final String JAVA_VM_VERSION
public static final String JAVA_IO_TMPDIR
public static final String USER_DIR
public static final String USER_HOME
public static final String USER_NAME
public static final String USER_TIMEZONE
public static final String USER_LANGUAGE
public static final String USER_COUNTRY
public static final String CURRENT_PATH
new File("./").getAbsolutePath()public static final String PATH_SEPARATOR
public static final String FILE_SEPARATOR
public static final String LINE_SEPARATOR
public static final int EOF
public static byte[] chars2Bytes(char[] chars)
chars - public static byte[] chars2Bytes(char[] chars,
Charset charset)
chars - charset - public static byte[] chars2Bytes(char[] chars,
int offset,
int len,
Charset charset)
chars - offset - len - charset - public static char[] bytes2Chars(byte[] bytes)
bytes - public static char[] bytes2Chars(byte[] bytes,
Charset charset)
bytes - charset - public static char[] bytes2Chars(byte[] bytes,
int offset,
int len,
Charset charset)
bytes - offset - len - charset - public static InputStream string2InputStream(String str)
str - public static InputStream string2InputStream(String str, Charset charset)
str - charset - public static Reader string2Reader(String str)
str - public static Writer stringBuilder2Writer(StringBuilder sb)
sb - public static byte[] readAllBytes(File file) throws UncheckedIOException
file - UncheckedIOException - the unchecked IO exceptionpublic static byte[] readAllBytes(InputStream is) throws UncheckedIOException
is - UncheckedIOException - the unchecked IO exceptionpublic static byte[] readBytes(File file) throws IOException
file - IOException - the unchecked IO exceptionreadAllBytes(File)public static byte[] readBytes(File file, long offset, int maxLen) throws IOException
file - offset - maxLen - IOExceptionpublic static byte[] readBytes(InputStream is) throws IOException
is - IOExceptionreadAllBytes(InputStream)public static byte[] readBytes(InputStream is, long offset, int maxLen) throws IOException
is - offset - maxLen - IOExceptionpublic static char[] readAllChars(File file) throws UncheckedIOException
file - UncheckedIOException - the unchecked IO exceptionpublic static char[] readAllChars(File file, Charset encoding) throws UncheckedIOException
file - encoding - UncheckedIOException - the unchecked IO exceptionpublic static char[] readAllChars(InputStream is) throws UncheckedIOException
is - UncheckedIOException - the unchecked IO exceptionpublic static char[] readAllChars(InputStream is, Charset encoding) throws UncheckedIOException
is - encoding - UncheckedIOException - the unchecked IO exceptionpublic static char[] readAllChars(Reader reader) throws UncheckedIOException
reader - UncheckedIOException - the unchecked IO exceptionpublic static char[] readChars(File file) throws IOException
file - IOExceptionreadAllChars(File)public static char[] readChars(File file, Charset encoding) throws IOException
file - encoding - IOExceptionreadAllChars(File, Charset)public static char[] readChars(File file, long offset, int maxLen) throws IOException
file - offset - maxLen - IOExceptionpublic static char[] readChars(File file, long offset, int maxLen, Charset encoding) throws IOException
file - offset - maxLen - encoding - IOExceptionpublic static char[] readChars(InputStream is) throws IOException
is - IOExceptionreadAllChars(InputStream)public static char[] readChars(InputStream is, Charset encoding) throws IOException
is - encoding - IOException#readAllChars(InputStream, encoding)public static char[] readChars(InputStream is, long offset, int maxLen) throws IOException
is - offset - maxLen - IOExceptionpublic static char[] readChars(InputStream is, long offset, int maxLen, Charset encoding) throws IOException
is - offset - maxLen - encoding - IOExceptionpublic static char[] readChars(Reader reader) throws IOException
reader - IOExceptionreadAllChars(Reader)public static char[] readChars(Reader reader, long offset, int maxLen) throws IOException
reader - offset - maxLen - IOExceptionpublic static String readString(File file) throws UncheckedIOException
String.file - UncheckedIOException - the unchecked IO exceptionpublic static String readString(File file, Charset encoding) throws UncheckedIOException
String.file - encoding - UncheckedIOException - the unchecked IO exceptionpublic static String readString(File file, long offset, int maxLen) throws UncheckedIOException
file - offset - maxLen - UncheckedIOException - the unchecked IO exceptionpublic static String readString(File file, long offset, int maxLen, Charset encoding) throws UncheckedIOException
file - offset - maxLen - encoding - UncheckedIOException - the unchecked IO exceptionpublic static String readString(InputStream is) throws UncheckedIOException
String.is - UncheckedIOException - the unchecked IO exceptionpublic static String readString(InputStream is, Charset encoding) throws UncheckedIOException
String.is - encoding - UncheckedIOException - the unchecked IO exceptionpublic static String readString(InputStream is, long offset, int maxLen) throws UncheckedIOException
is - offset - maxLen - UncheckedIOException - the unchecked IO exceptionpublic static String readString(InputStream is, long offset, int maxLen, Charset encoding) throws UncheckedIOException
is - offset - maxLen - encoding - UncheckedIOException - the unchecked IO exceptionpublic static String readString(Reader reader) throws UncheckedIOException
String.reader - UncheckedIOException - the unchecked IO exceptionpublic static String readString(Reader reader, long offset, int maxLen) throws UncheckedIOException
reader - offset - maxLen - UncheckedIOException - the unchecked IO exceptionpublic static List<String> readAllLines(File file) throws UncheckedIOException
file - UncheckedIOException - the unchecked IO exceptionpublic static List<String> readAllLines(File file, Charset encoding) throws UncheckedIOException
file - encoding - UncheckedIOException - the unchecked IO exceptionpublic static List<String> readAllLines(InputStream is) throws UncheckedIOException
is - UncheckedIOException - the unchecked IO exceptionpublic static List<String> readAllLines(InputStream is, Charset encoding) throws UncheckedIOException
is - encoding - UncheckedIOException - the unchecked IO exceptionpublic static List<String> readAllLines(Reader reader) throws UncheckedIOException
reader - UncheckedIOException - the unchecked IO exceptionpublic static String readLine(File file) throws IOException
file - IOExceptionpublic static String readLine(File file, int lineIndex) throws IOException
file - lineIndex - IOExceptionpublic static String readLine(File file, int lineIndex, Charset encoding) throws IOException
file - lineIndex - encoding - IOExceptionpublic static String readLine(InputStream is) throws IOException
is - IOExceptionpublic static String readLine(InputStream is, int lineIndex) throws IOException
is - lineIndex - IOExceptionpublic static String readLine(InputStream is, int lineIndex, Charset encoding) throws IOException
is - lineIndex - encoding - IOExceptionpublic static String readLine(Reader reader) throws IOException
reader - IOExceptionpublic static String readLine(Reader reader, int lineIndex) throws IOException
reader - lineIndex - IOExceptionpublic static List<String> readLines(File file) throws IOException
file - IOExceptionreadAllLines(File)public static List<String> readLines(File file, Charset encoding) throws IOException
file - encoding - IOExceptionreadAllLines(File, Charset)public static List<String> readLines(File file, int offset, int count) throws IOException
file - offset - count - IOExceptionpublic static List<String> readLines(File file, int offset, int count, Charset encoding) throws IOException
file - offset - count - encoding - IOExceptionpublic static List<String> readLines(InputStream is) throws IOException
is - IOException#readAllLines(is)public static List<String> readLines(InputStream is, Charset encoding) throws IOException
is - encoding - IOException#readAllLines(is, Charset)public static List<String> readLines(InputStream is, int offset, int count) throws IOException
is - offset - count - IOExceptionpublic static List<String> readLines(InputStream is, int offset, int count, Charset encoding) throws IOException
is - offset - count - encoding - IOExceptionpublic static List<String> readLines(Reader reader) throws IOException
reader - IOExceptionreadAllLines(Reader)public static List<String> readLines(Reader reader, int offset, int count) throws IOException
reader - offset - count - IOExceptionpublic static int read(File file, byte[] buf) throws IOException
file - buf - IOExceptionpublic static int read(File file, byte[] buf, int off, int len) throws IOException
file - buf - off - the start offset in array b at which the data is written.len - IOExceptionpublic static int read(InputStream is, byte[] buf) throws IOException
is - buf - IOException - Signals that an I/O exception has occurred.public static int read(InputStream is, byte[] buf, int off, int len) throws IOException
is - buf - off - the start offset in array b at which the data is written.len - IOException - Signals that an I/O exception has occurred.public static int read(File file, char[] buf) throws IOException
file - buf - IOExceptionpublic static int read(File file, char[] buf, Charset charset) throws IOException
file - buf - charset - IOExceptionpublic static int read(File file, char[] buf, int off, int len) throws IOException
file - buf - off - the start offset in array b at which the data is written.len - IOExceptionpublic static int read(File file, char[] buf, int off, int len, Charset charset) throws IOException
file - buf - off - len - charset - IOExceptionpublic static int read(Reader reader, char[] buf) throws IOException
reader - buf - IOException - Signals that an I/O exception has occurred.public static int read(Reader reader, char[] buf, int off, int len) throws IOException
reader - buf - off - the start offset in array b at which the data is written.len - IOException - Signals that an I/O exception has occurred.public static void writeLine(File file, Object obj) throws IOException
file - obj - IOExceptionpublic static void writeLine(OutputStream os, Object obj) throws IOException
os - obj - IOExceptionpublic static void writeLine(OutputStream os, Object obj, boolean flush) throws IOException
os - obj - flush - IOExceptionpublic static void writeLine(Writer writer, Object obj) throws IOException
writer - obj - IOExceptionpublic static void writeLine(Writer writer, Object obj, boolean flush) throws IOException
writer - obj - flush - IOExceptionpublic static void writeLines(File file, Object[] lines) throws IOException
file - lines - IOExceptionpublic static void writeLines(File file, Object[] lines, int offset, int count) throws IOException
file - lines - offset - count - IOExceptionpublic static void writeLines(OutputStream os, Object[] lines) throws IOException
os - lines - IOExceptionpublic static void writeLines(OutputStream os, Object[] lines, boolean flush) throws IOException
os - lines - flush - IOExceptionpublic static void writeLines(OutputStream os, Object[] lines, int offset, int count) throws IOException
os - lines - offset - count - IOExceptionpublic static void writeLines(OutputStream os, Object[] lines, int offset, int count, boolean flush) throws IOException
os - lines - offset - count - flush - IOExceptionpublic static void writeLines(Writer writer, Object[] lines) throws IOException
writer - lines - IOExceptionpublic static void writeLines(Writer writer, Object[] lines, boolean flush) throws IOException
writer - lines - flush - IOExceptionpublic static void writeLines(Writer writer, Object[] lines, int offset, int count) throws IOException
writer - lines - offset - count - IOExceptionpublic static void writeLines(Writer writer, Object[] lines, int offset, int count, boolean flush) throws IOException
writer - lines - offset - count - flush - IOExceptionpublic static void writeLines(File file, Collection<?> lines) throws IOException
file - lines - IOExceptionpublic static void writeLines(File file, Collection<?> lines, int offset, int count) throws IOException
file - lines - offset - count - IOExceptionpublic static void writeLines(OutputStream os, Collection<?> lines) throws IOException
os - lines - IOExceptionpublic static void writeLines(OutputStream os, Collection<?> lines, boolean flush) throws IOException
os - lines - flush - IOExceptionpublic static void writeLines(OutputStream os, Collection<?> lines, int offset, int count) throws IOException
os - lines - offset - count - IOExceptionpublic static void writeLines(OutputStream os, Collection<?> lines, int offset, int count, boolean flush) throws IOException
os - lines - offset - count - flush - IOExceptionpublic static void writeLines(Writer writer, Collection<?> lines) throws IOException
writer - lines - IOExceptionpublic static void writeLines(Writer writer, Collection<?> lines, boolean flush) throws IOException
writer - lines - flush - IOExceptionpublic static void writeLines(Writer writer, Collection<?> lines, int offset, int count) throws IOException
writer - lines - offset - count - IOExceptionpublic static void writeLines(Writer writer, Collection<?> lines, int offset, int count, boolean flush) throws IOException
writer - lines - offset - count - flush - IOExceptionpublic static void write(Writer writer, boolean b) throws IOException
writer - b - IOException - Signals that an I/O exception has occurred.public static void write(Writer writer, boolean b, boolean flush) throws IOException
writer - b - flush - IOException - Signals that an I/O exception has occurred.public static void write(Writer writer, char c) throws IOException
writer - c - IOException - Signals that an I/O exception has occurred.public static void write(Writer writer, char c, boolean flush) throws IOException
writer - c - flush - IOException - Signals that an I/O exception has occurred.public static void write(Writer writer, byte b) throws IOException
writer - b - IOException - Signals that an I/O exception has occurred.public static void write(Writer writer, byte b, boolean flush) throws IOException
writer - b - flush - IOException - Signals that an I/O exception has occurred.public static void write(Writer writer, short s) throws IOException
writer - s - IOException - Signals that an I/O exception has occurred.public static void write(Writer writer, short s, boolean flush) throws IOException
writer - s - flush - IOException - Signals that an I/O exception has occurred.public static void write(Writer writer, int i) throws IOException
writer - i - IOException - Signals that an I/O exception has occurred.public static void write(Writer writer, int i, boolean flush) throws IOException
writer - i - flush - IOException - Signals that an I/O exception has occurred.public static void write(Writer writer, long lng) throws IOException
writer - lng - IOException - Signals that an I/O exception has occurred.public static void write(Writer writer, long lng, boolean flush) throws IOException
writer - lng - flush - IOException - Signals that an I/O exception has occurred.public static void write(Writer writer, float f) throws IOException
writer - f - IOException - Signals that an I/O exception has occurred.public static void write(Writer writer, float f, boolean flush) throws IOException
writer - f - flush - IOException - Signals that an I/O exception has occurred.public static void write(Writer writer, double d) throws IOException
writer - d - IOException - Signals that an I/O exception has occurred.public static void write(Writer writer, double d, boolean flush) throws IOException
writer - d - flush - IOException - Signals that an I/O exception has occurred.public static void write(File output, CharSequence str) throws IOException
output - str - IOExceptionpublic static void write(File output, CharSequence str, Charset charset) throws IOException
output - str - charset - IOExceptionpublic static void write(OutputStream output, CharSequence str) throws IOException
output - str - IOExceptionpublic static void write(OutputStream output, CharSequence str, Charset charset) throws IOException
output - str - charset - IOExceptionpublic static void write(OutputStream output, CharSequence str, boolean flush) throws IOException
output - str - flush - IOExceptionpublic static void write(OutputStream output, CharSequence str, Charset charset, boolean flush) throws IOException
output - str - charset - flush - IOExceptionpublic static void write(Writer output, CharSequence str) throws IOException
output - str - IOExceptionpublic static void write(Writer output, CharSequence str, boolean flush) throws IOException
output - str - flush - IOExceptionpublic static void write(File output, char[] chars) throws IOException
output - chars - IOExceptionpublic static void write(File output, char[] chars, Charset charset) throws IOException
output - chars - charset - IOExceptionpublic static void write(File output, char[] chars, int offset, int len) throws IOException
output - chars - offset - len - IOExceptionpublic static void write(File output, char[] chars, int offset, int len, Charset charset) throws IOException
output - chars - offset - len - charset - IOExceptionpublic static void write(OutputStream output, char[] chars) throws IOException
output - chars - IOExceptionpublic static void write(OutputStream output, char[] chars, Charset charset) throws IOException
output - chars - charset - IOExceptionpublic static void write(OutputStream output, char[] chars, int offset, int len) throws IOException
output - chars - offset - len - IOExceptionpublic static void write(OutputStream output, char[] chars, int offset, int len, Charset charset) throws IOException
output - chars - offset - len - charset - IOExceptionpublic static void write(OutputStream output, char[] chars, boolean flush) throws IOException
output - chars - flush - IOExceptionpublic static void write(OutputStream output, char[] chars, int offset, int len, boolean flush) throws IOException
output - chars - offset - len - flush - IOExceptionpublic static void write(OutputStream output, char[] chars, int offset, int len, Charset charset, boolean flush) throws IOException
output - chars - offset - len - charset - flush - IOExceptionpublic static void write(Writer output, char[] chars) throws IOException
output - chars - IOExceptionpublic static void write(Writer output, char[] chars, int offset, int len) throws IOException
output - chars - offset - len - IOExceptionpublic static void write(Writer output, char[] chars, boolean flush) throws IOException
output - chars - flush - IOExceptionpublic static void write(Writer output, char[] chars, int offset, int len, boolean flush) throws IOException
output - chars - offset - len - flush - IOExceptionpublic static void write(File output, byte[] bytes) throws IOException
output - bytes - IOExceptionpublic static void write(File output, byte[] bytes, int offset, int len) throws IOException
output - bytes - offset - len - IOExceptionpublic static void write(OutputStream output, byte[] bytes) throws IOException
output - bytes - IOExceptionpublic static void write(OutputStream output, byte[] bytes, int offset, int len) throws IOException
output - bytes - offset - len - IOExceptionpublic static void write(OutputStream output, byte[] bytes, boolean flush) throws IOException
output - bytes - flush - IOExceptionpublic static void write(OutputStream output, byte[] bytes, int offset, int len, boolean flush) throws IOException
output - bytes - offset - len - flush - IOExceptionpublic static long write(File output, InputStream input) throws IOException
output - input - IOExceptionpublic static long write(File output, InputStream input, long offset, long len) throws IOException
output - input - offset - by bytelen - by byteIOExceptionpublic static long write(OutputStream output, InputStream input) throws IOException
output - input - IOExceptionpublic static long write(OutputStream output, InputStream input, long offset, long len) throws IOException
output - input - offset - len - IOExceptionpublic static long write(OutputStream output, InputStream input, boolean flush) throws IOException
output - input - flush - IOExceptionpublic static long write(OutputStream output, InputStream input, long offset, long len, boolean flush) throws IOException
output - input - offset - by bytelen - by byteflush - IOExceptionpublic static long write(File output, Reader input) throws IOException
output - input - IOExceptionpublic static long write(File output, Reader input, Charset charset) throws IOException
output - input - charset - IOExceptionpublic static long write(File output, Reader input, long offset, long len) throws IOException
output - input - offset - len - IOExceptionpublic static long write(File output, Reader input, long offset, long len, Charset charset) throws IOException
output - input - offset - by charlen - by charcharset - IOExceptionpublic static long write(Writer output, Reader input) throws IOException
output - input - IOExceptionpublic static long write(Writer output, Reader input, long offset, long len) throws IOException
output - input - offset - len - IOExceptionpublic static long write(Writer output, Reader input, boolean flush) throws IOException
output - input - flush - IOExceptionpublic static long write(Writer output, Reader input, long offset, long len, boolean flush) throws IOException
output - input - offset - by charlen - by charflush - IOExceptionpublic static long write(File output, File input) throws IOException
output - input - IOExceptionpublic static long write(File output, File input, long offset, long len) throws IOException
output - input - offset - len - IOExceptionpublic static long write(OutputStream output, File input) throws IOException
output - input - IOExceptionpublic static long write(OutputStream output, File input, long offset, long len) throws IOException
output - input - offset - len - IOExceptionpublic static long write(OutputStream output, File input, boolean flush) throws IOException
output - input - flush - IOExceptionpublic static long write(OutputStream output, File input, long offset, long len, boolean flush) throws IOException
output - input - offset - by bytelen - by byteflush - IOExceptionpublic static long write(Writer output, File input) throws IOException
output - input - IOExceptionpublic static long write(Writer output, File input, long offset, long len) throws IOException
output - input - offset - len - IOExceptionpublic static long write(Writer output, File input, boolean flush) throws IOException
output - input - flush - IOExceptionpublic static long write(Writer output, File input, long offset, long len, boolean flush) throws IOException
output - input - offset - by charlen - by charflush - IOExceptionpublic static void append(File output, byte[] bytes) throws IOException
output - bytes - IOExceptionpublic static void append(File output, byte[] bytes, int offset, int len) throws IOException
output - bytes - offset - len - IOExceptionpublic static void append(File output, char[] chars) throws IOException
output - chars - IOExceptionpublic static void append(File output, char[] chars, Charset charset) throws IOException
output - chars - charset - IOExceptionpublic static void append(File output, char[] chars, int offset, int len) throws IOException
output - chars - offset - len - IOExceptionpublic static void append(File output, char[] chars, int offset, int len, Charset charset) throws IOException
output - chars - offset - len - charset - IOExceptionpublic static void append(File output, CharSequence str) throws IOException
output - str - IOExceptionpublic static void append(File output, CharSequence str, Charset charset) throws IOException
output - str - charset - IOExceptionpublic static long append(File output, InputStream input) throws IOException
output - input - IOExceptionpublic static long append(File output, InputStream input, long offset, long len) throws IOException
output - input - offset - by bytelen - by byteIOExceptionpublic static long append(File output, Reader input) throws IOException
output - input - IOExceptionpublic static long append(File output, Reader input, Charset charset) throws IOException
output - input - charset - IOExceptionpublic static long append(File output, Reader input, long offset, long len) throws IOException
output - input - offset - len - IOExceptionpublic static long append(File output, Reader input, long offset, long len, Charset charset) throws IOException
output - input - offset - by charlen - by charcharset - IOExceptionpublic static long append(File output, File input) throws IOException
output - input - IOExceptionpublic static long append(File output, File input, long offset, long len) throws IOException
output - input - offset - len - IOExceptionpublic static void appendLine(File output, CharSequence str) throws IOException
output - str - IOExceptionpublic static void appendLine(File output, CharSequence str, Charset charset) throws IOException
output - str - charset - IOExceptionpublic static long skip(InputStream input, long toSkip) throws IOException
input - toSkip - IOExceptionpublic static long skip(Reader input, long toSkip) throws IOException
input - toSkip - IOExceptionpublic static void skipFully(InputStream input, long toSkip) throws IOException
input - toSkip - IOException - if the remaining length of the specified input is less than the specified toSkippublic static void skipFully(Reader input, long toSkip) throws IOException
input - toSkip - IOException - if the remaining length of the specified input is less than the specified toSkippublic static MappedByteBuffer map(File file) throws IOException
file - IOExceptionpublic static MappedByteBuffer map(File file, FileChannel.MapMode mode) throws IOException
FileChannel.map(java.nio.channels.FileChannel.MapMode, long, long)
using the requested FileChannel.MapMode.
Files are mapped from offset 0 to its length.
This only works for files <= Integer.MAX_VALUE bytes.
file - the file to mapmode - the mode to use when mapping filefileIOExceptionFileChannel.map(MapMode, long, long)public static MappedByteBuffer map(File file, FileChannel.MapMode mode, long offset, long len) throws IOException
FileChannel.map(java.nio.channels.FileChannel.MapMode, long, long)
using the requested FileChannel.MapMode.
Files are mapped from offset 0 to size.
If the mode is FileChannel.MapMode.READ_WRITE and the file does not exist,
it will be created with the requested size. Thus this method is
useful for creating memory mapped files which do not yet exist.
This only works for files <= Integer.MAX_VALUE bytes.
file - the file to mapmode - the mode to use when mapping fileoffset - len - fileIOExceptionFileChannel.map(MapMode, long, long)public static String simplifyPath(String pathname)
These heuristics do not always match the behavior of the filesystem. In
particular, consider the path a/../b, which simplifyPath
will change to b. If a is a symlink to x, a/../b may refer to a sibling of x, rather than the sibling of
a referred to by b.
pathname - public static String getFileExtension(String fullName)
.'.fullName - public static String getNameWithoutExtension(String file)
basename unix command. The result does not include the '.'.file - The name of the file to trim the extension from. This can be either a fully
qualified file name (including a path) or just a file name.public static BufferedReader newBufferedReader(File file) throws UncheckedIOException
file - UncheckedIOException - the unchecked IO exceptionpublic static BufferedReader newBufferedReader(File file, Charset charset) throws UncheckedIOException
file - charset - UncheckedIOException - the unchecked IO exceptionpublic static BufferedReader newBufferedReader(Path path) throws UncheckedIOException
path - UncheckedIOException - the unchecked IO exceptionpublic static BufferedReader newBufferedReader(Path path, Charset charset) throws UncheckedIOException
path - charset - UncheckedIOException - the unchecked IO exceptionpublic static BufferedReader newBufferedReader(InputStream is) throws UncheckedIOException
is - UncheckedIOException - the unchecked IO exceptionpublic static BufferedReader newBufferedReader(InputStream is, Charset charset) throws UncheckedIOException
is - charset - UncheckedIOException - the unchecked IO exceptionpublic static BufferedWriter newBufferedWriter(File file) throws UncheckedIOException
file - UncheckedIOException - the unchecked IO exceptionpublic static BufferedWriter newBufferedWriter(File file, Charset charset) throws UncheckedIOException
file - charset - UncheckedIOException - the unchecked IO exceptionpublic static BufferedWriter newBufferedWriter(OutputStream os)
os - public static BufferedWriter newBufferedWriter(OutputStream os, Charset charset)
os - charset - public static LZ4BlockInputStream newLZ4BlockInputStream(InputStream is)
is - public static LZ4BlockOutputStream newLZ4BlockOutputStream(OutputStream os)
os - public static LZ4BlockOutputStream newLZ4BlockOutputStream(OutputStream os, int blockSize)
os - blockSize - public static SnappyInputStream newSnappyInputStream(InputStream is) throws UncheckedIOException
is - UncheckedIOException - the unchecked IO exceptionpublic static SnappyOutputStream newSnappyOutputStream(OutputStream os)
os - public static SnappyOutputStream newSnappyOutputStream(OutputStream os, int bufferSize)
os - bufferSize - public static GZIPInputStream newGZIPInputStream(InputStream is) throws UncheckedIOException
is - UncheckedIOException - the unchecked IO exceptionpublic static GZIPInputStream newGZIPInputStream(InputStream is, int bufferSize) throws UncheckedIOException
is - bufferSize - UncheckedIOException - the unchecked IO exceptionpublic static GZIPOutputStream newGZIPOutputStream(OutputStream os) throws UncheckedIOException
os - UncheckedIOException - the unchecked IO exceptionpublic static GZIPOutputStream newGZIPOutputStream(OutputStream os, int bufferSize) throws UncheckedIOException
os - bufferSize - UncheckedIOException - the unchecked IO exceptionpublic static void close(AutoCloseable closeable)
closeable - @SafeVarargs public static void closeAll(AutoCloseable... a)
a - public static void closeAll(Collection<? extends AutoCloseable> c)
c - public static void closeQuietly(AutoCloseable closeable)
closeable - @SafeVarargs public static void closeAllQuietly(AutoCloseable... a)
a - public static void closeAllQuietly(Collection<? extends AutoCloseable> c)
c - public static void copyFileToDirectory(File srcFile, File destDir) throws UncheckedIOException
srcFile - destDir - UncheckedIOException - the unchecked IO exceptionpublic static void copyFileToDirectory(File srcFile, File destDir, boolean preserveFileDate) throws UncheckedIOException
srcFile - destDir - preserveFileDate - UncheckedIOException - the unchecked IO exceptionpublic static <E extends Exception> void copyFileToDirectory(File srcFile, File destDir, boolean preserveFileDate, Throwables.BiPredicate<? super File,? super File,E> filter) throws UncheckedIOException, E extends Exception
scrFile if it's a file or its sub files/directories if it's a directory to the target destDir with the specified filter.E - srcFile - destDir - preserveFileDate - filter - UncheckedIOException - the unchecked IO exceptionE - the eE extends Exception@SafeVarargs public static Path copy(Path source, Path target, CopyOption... options) throws UncheckedIOException
source - target - options - UncheckedIOException - the unchecked IO exceptionFiles.copy(Path, Path, CopyOption...)@SafeVarargs public static long copy(InputStream in, Path target, CopyOption... options) throws UncheckedIOException
in - target - options - UncheckedIOException - the unchecked IO exceptionFiles.copy(InputStream, Path, CopyOption...)public static long copy(Path source, OutputStream output) throws UncheckedIOException
source - output - UncheckedIOException - the unchecked IO exceptionFiles.copy(Path, OutputStream)public static void copyURLToFile(URL source, File destination) throws UncheckedIOException
source to a file
destination. The directories up to destination
will be created if they don't already exist. destination
will be overwritten if it already exists.
Warning: this method does not set a connection or read timeout and thus
might block forever. Use copyURLToFile(URL, File, int, int)
with reasonable timeouts to prevent this.
source the URL to copy bytes from, must not be null
destination the non-directory File to write bytes to
(possibly overwriting), must not be null
UncheckedIOException - if an IO error occurs during copyingpublic static void copyURLToFile(URL source, File destination, int connectionTimeout, int readTimeout) throws UncheckedIOException
source to a file
destination. The directories up to destination
will be created if they don't already exist. destination
will be overwritten if it already exists.
source the URL to copy bytes from, must not be null
destination the non-directory File to write bytes to
(possibly overwriting), must not be nullconnectionTimeout - the number of milliseconds until this method
will timeout if no connection could be established to the sourcereadTimeout - the number of milliseconds until this method will
timeout if no data could be read from the sourceUncheckedIOException - if an IO error occurs during copyingpublic static void move(File srcFile, File destDir) throws UncheckedIOException
srcFile - destDir - UncheckedIOException - the unchecked IO exceptionpublic static boolean renameTo(File srcFile, String newFileName)
srcFile - newFileName - true if and only if the renaming succeeded;
false otherwisepublic static boolean deleteIfExists(File file)
file - public static boolean deleteAllIfExists(File file)
file - public static boolean deleteFiles(File dir)
dir - false if the file or some of its sub files if it's directory can't be deleted.public static <E extends Exception> boolean deleteFiles(File dir, Throwables.BiPredicate<? super File,? super File,E> filter) throws E extends Exception
dir if it's a file or its sub files/directories if it's a directory with the specified filter.E - dir - filter - false if the file or some of its sub files if it's directory can't be deleted.E - the eE extends Exceptionpublic static boolean cleanDirectory(File directory)
directory - directory to cleanfalse if some of its sub files can't be deleted.deleteFiles(java.io.File)public static boolean createIfNotExists(File file) throws UncheckedIOException
file - false if file exists or failed to create new file.UncheckedIOException - the unchecked IO exceptionpublic static boolean mkdirIfNotExists(File dir)
public static boolean mkdirsIfNotExists(File dir)
public static boolean isFileNewer(File file, Date date)
File is newer than the specified Date.file - the File of which the modification date must be compareddate - the date referenceFile exists and has been modified after the given Date.IllegalArgumentException - if the file or date is nullpublic static boolean isFileNewer(File file, File reference)
File is newer than the reference File.file - the File of which the modification date must be comparedreference - the File of which the modification date is usedFile exists and has been modified more recently than the reference FileIllegalArgumentException - if the file or reference file is null or the reference file doesn't existpublic static boolean isFileOlder(File file, Date date)
File is older than the specified Date.file - the File of which the modification date must be compareddate - the date referenceFile exists and has been modified before the given DateIllegalArgumentException - if the file or date is nullpublic static boolean isFileOlder(File file, File reference)
File is older than the reference File.file - the File of which the modification date must be comparedreference - the File of which the modification date is usedFile exists and has been modified before the reference FileIllegalArgumentException - if the file or reference file is null or the reference file doesn't existpublic static boolean isSymbolicLink(File file)
Will not return true if there is a Symbolic Link anywhere in the path, only if the specific file is.
When using jdk1.7, this method delegates to boolean java.nio.file.Files.isSymbolicLink(Path path)
Note: the current implementation always returns false if running on
jkd1.6 and the system is detected as Windows using FilenameUtil#isSystemWindows()
For code that runs on Java 1.7 or later, use the following method instead:
boolean java.nio.file.Files.isSymbolicLink(Path path)file - the file to checkpublic static long sizeOf(File file)
File is a regular file, then the file's length is returned.
If the argument is a directory, then the size of the directory is
calculated recursively. If a directory or subdirectory is security
restricted, its size will not be included.
Note that overflow is not detected, and the return value may be negative if
overflow occurs. See #sizeOfAsBigInteger(File) for an alternative
method that does not overflow.
file - the regular file or directory to return the size
of (must not be null).IllegalArgumentException - if the file is null or the file does not exist.public static long sizeOfDirectory(File directory)
Note that overflow is not detected, and the return value may be negative if
overflow occurs. See #sizeOfDirectoryAsBigInteger(File) for an alternative
method that does not overflow.
directory - directory to inspect, must not be nullLong.MAX_VALUE.IllegalArgumentException - if the directory is null or it's not existed directory.public static void zip(File sourceFile, File targetFile) throws UncheckedIOException
sourceFile - targetFile - UncheckedIOException - the unchecked IO exceptionpublic static void zip(Collection<File> sourceFiles, File targetFile) throws UncheckedIOException
sourceFiles - targetFile - UncheckedIOException - the unchecked IO exceptionpublic static void unzip(File srcZipFile, File targetDir)
srcZipFile - targetDir - public static void split(File file, int countOfParts) throws UncheckedIOException
file - countOfParts - UncheckedIOException - the unchecked IO exceptionpublic static void split(File file, int countOfParts, File destDir) throws UncheckedIOException
file - countOfParts - destDir - UncheckedIOException - the unchecked IO exceptionpublic static void splitBySize(File file, long sizeOfPart) throws UncheckedIOException
file - sizeOfPart - UncheckedIOException - the unchecked IO exceptionpublic static void splitBySize(File file, long sizeOfPart, File destDir) throws UncheckedIOException
file - sizeOfPart - destDir - UncheckedIOException - the unchecked IO exceptionpublic static long merge(File[] sourceFiles, File destFile) throws UncheckedIOException
sourceFiles - destFile - UncheckedIOException - the unchecked IO exceptionpublic static long merge(Collection<File> sourceFiles, File destFile) throws UncheckedIOException
sourceFiles - destFile - UncheckedIOException - the unchecked IO exceptionpublic static List<String> list(File parentPath, boolean recursively, boolean excludeDirectory)
parentPath - recursively - excludeDirectory - public static <E extends Exception> List<String> list(File parentPath, boolean recursively, Throwables.BiPredicate<? super File,? super File,E> filter) throws E extends Exception
E - parentPath - recursively - filter - E - the eE extends Exceptionpublic static List<File> listFiles(File parentPath, boolean recursively, boolean excludeDirectory)
parentPath - recursively - excludeDirectory - public static <E extends Exception> List<File> listFiles(File parentPath, boolean recursively, Throwables.BiPredicate<? super File,? super File,E> filter) throws E extends Exception
E - parentPath - recursively - filter - E - the eE extends Exceptionpublic static List<File> listDirectories(File parentPath)
parentPath - public static List<File> listDirectories(File parentPath, boolean recursively)
parentPath - recursively - public static File toFile(URL url)
URL to a File.
From version 1.1 this method will decode the URL.
Syntax such as file:///my%20docs/file.txt will be
correctly decoded to /my docs/file.txt. Starting with version
1.5, this method uses UTF-8 to decode percent-encoded octets to characters.
Additionally, malformed percent-encoded octets are handled leniently by
passing them through literally.
url the file URL to convert, null returns null
NullPointerException - if the parameter is nullpublic static File[] toFiles(URL[] urls) throws UncheckedIOException
URL to a File.
Returns an array of the same size as the input.
If the input is null, an empty array is returned.
If the input contains null, the output array contains null at the same
index.
This method will decode the URL.
Syntax such as file:///my%20docs/file.txt will be
correctly decoded to /my docs/file.txt.
urls the file URLs to convert, null returns empty array
null array of Files matching the input, with a null item
if there was a null at that index in the input arrayUncheckedIOException - the unchecked IO exceptionIllegalArgumentException - if any file is incorrectly encodedpublic static List<File> toFiles(Collection<URL> urls) throws UncheckedIOException
urls - UncheckedIOException - the unchecked IO exceptionpublic static URL toURL(File file) throws UncheckedIOException
file - UncheckedIOException - the unchecked IO exceptionpublic static URL[] toURLs(File[] files) throws UncheckedIOException
files - UncheckedIOException - the unchecked IO exceptionpublic static List<URL> toURLs(Collection<File> files) throws UncheckedIOException
files - UncheckedIOException - the unchecked IO exceptionpublic static boolean touch(File file)
file - the File to touchCopyright © 2021. All rights reserved.