public final class FileUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.nio.charset.Charset |
CHARSET |
static long |
ONE_GIB |
static long |
ONE_KIB |
static long |
ONE_MIB |
static long |
ONE_TIB |
Modifier and Type | Method and Description |
---|---|
static void |
append(File file,
java.lang.String... lines) |
static void |
appendAndSync(File file,
java.lang.String... lines) |
static void |
clean(java.nio.ByteBuffer buffer) |
static void |
close(java.io.Closeable... cs) |
static void |
close(java.lang.Iterable<? extends java.io.Closeable> cs) |
static void |
closeQuietly(java.lang.AutoCloseable c) |
static void |
closeQuietly(java.io.Closeable c) |
static void |
closeQuietly(java.lang.Iterable<? extends java.lang.AutoCloseable> cs) |
static void |
copyWithConfirm(File from,
File to) |
static void |
copyWithConfirm(java.lang.String from,
java.lang.String to) |
static void |
copyWithOutConfirm(java.lang.String from,
java.lang.String to) |
static File |
createDeletableTempFile(java.lang.String prefix,
java.lang.String suffix) |
static void |
createDirectory(File directory)
Deprecated.
|
static void |
createDirectory(java.lang.String directory)
Deprecated.
|
static void |
createHardLink(File from,
File to) |
static void |
createHardLink(java.lang.String from,
java.lang.String to) |
static void |
createHardLinkWithConfirm(File from,
File to) |
static void |
createHardLinkWithConfirm(java.lang.String from,
java.lang.String to) |
static void |
createHardLinkWithoutConfirm(java.lang.String from,
java.lang.String to) |
static File |
createTempFile(java.lang.String prefix,
java.lang.String suffix) |
static File |
createTempFile(java.lang.String prefix,
java.lang.String suffix,
File directory)
Pretty much like
File.createTempFile(String, String, java.io.File) , but with
the guarantee that the "random" part of the generated file name between
prefix and suffix is a positive, increasing long value. |
static void |
delete(File... files)
Deprecated.
|
static boolean |
delete(java.lang.String file)
Deprecated.
|
static void |
deleteDirectoryIfEmpty(java.nio.file.Path path)
Deletes the specified directory if it is empty
|
static void |
deleteRecursive(File dir)
Deprecated.
|
static void |
deleteRecursiveOnExit(File dir)
Deprecated.
|
static void |
deleteRecursiveWithThrottle(File dir,
com.google.common.util.concurrent.RateLimiter rateLimiter)
Deprecated.
|
static void |
deleteWithConfirm(File file)
Deprecated.
|
static java.lang.Throwable |
deleteWithConfirm(File file,
java.lang.Throwable accumulate)
Deprecated.
|
static java.lang.Throwable |
deleteWithConfirm(File file,
java.lang.Throwable accumulate,
com.google.common.util.concurrent.RateLimiter rateLimiter)
Deprecated.
|
static void |
deleteWithConfirm(java.lang.String file)
Deprecated.
|
static long |
folderSize(File folder)
Get the size of a directory in bytes
|
static java.lang.String |
getCanonicalPath(File file) |
static java.lang.String |
getCanonicalPath(java.lang.String filename) |
static File |
getTempDir() |
static void |
handleCorruptSSTable(CorruptSSTableException e) |
static void |
handleFSError(FSError e) |
static void |
handleFSErrorAndPropagate(FSError e)
handleFSErrorAndPropagate will invoke the disk failure policy error handler,
which may or may not stop the daemon or transports.
|
static void |
handleStartupFSError(java.lang.Throwable t) |
static boolean |
isContained(File folder,
File file)
Return true if file is contained in folder
|
static boolean |
isSubDirectory(File parent,
File child)
Deprecated.
|
static void |
moveRecursively(java.nio.file.Path source,
java.nio.file.Path target)
Moves the contents of a directory to another directory.
|
static long |
parseFileSize(java.lang.String value) |
static java.util.List<java.lang.String> |
readLines(File file) |
static void |
renameWithConfirm(File from,
File to)
Deprecated.
|
static void |
renameWithConfirm(java.lang.String from,
java.lang.String to)
Deprecated.
|
static void |
renameWithOutConfirm(java.lang.String from,
java.lang.String to)
Deprecated.
|
static void |
replace(File file,
java.lang.String... lines) |
static void |
setFSErrorHandler(FSErrorHandler handler) |
static java.lang.String |
stringifyFileSize(double value) |
static void |
truncate(java.lang.String path,
long size) |
static void |
write(File file,
java.util.List<java.lang.String> lines,
java.nio.file.StandardOpenOption... options)
Write lines to a file adding a newline to the end of each supplied line using the provided open options.
|
public static final java.nio.charset.Charset CHARSET
public static final long ONE_KIB
public static final long ONE_MIB
public static final long ONE_GIB
public static final long ONE_TIB
public static File getTempDir()
public static File createTempFile(java.lang.String prefix, java.lang.String suffix, File directory)
File.createTempFile(String, String, java.io.File)
, but with
the guarantee that the "random" part of the generated file name between
prefix
and suffix
is a positive, increasing long
value.public static File createTempFile(java.lang.String prefix, java.lang.String suffix)
public static File createDeletableTempFile(java.lang.String prefix, java.lang.String suffix)
public static void createHardLink(java.lang.String from, java.lang.String to)
public static void createHardLinkWithConfirm(java.lang.String from, java.lang.String to)
public static void createHardLinkWithoutConfirm(java.lang.String from, java.lang.String to)
public static void copyWithOutConfirm(java.lang.String from, java.lang.String to)
public static void copyWithConfirm(java.lang.String from, java.lang.String to)
public static void truncate(java.lang.String path, long size)
public static void closeQuietly(java.io.Closeable c)
public static void closeQuietly(java.lang.AutoCloseable c)
public static void close(java.io.Closeable... cs) throws java.io.IOException
java.io.IOException
public static void close(java.lang.Iterable<? extends java.io.Closeable> cs) throws java.io.IOException
java.io.IOException
public static void closeQuietly(java.lang.Iterable<? extends java.lang.AutoCloseable> cs)
public static java.lang.String getCanonicalPath(java.lang.String filename)
public static java.lang.String getCanonicalPath(File file)
public static boolean isContained(File folder, File file)
public static void clean(java.nio.ByteBuffer buffer)
public static long parseFileSize(java.lang.String value)
public static java.lang.String stringifyFileSize(double value)
public static void handleCorruptSSTable(CorruptSSTableException e)
public static void handleFSError(FSError e)
public static void handleStartupFSError(java.lang.Throwable t)
public static void handleFSErrorAndPropagate(FSError e)
e
- A filesystem errorpublic static long folderSize(File folder)
folder
- The directory for which we need size.public static void append(File file, java.lang.String... lines)
public static void appendAndSync(File file, java.lang.String... lines)
public static void replace(File file, java.lang.String... lines)
public static void write(File file, java.util.List<java.lang.String> lines, java.nio.file.StandardOpenOption... options)
file
- lines
- options
- public static java.util.List<java.lang.String> readLines(File file)
public static void setFSErrorHandler(FSErrorHandler handler)
@Deprecated public static void createDirectory(java.lang.String directory)
@Deprecated public static void createDirectory(File directory)
@Deprecated public static boolean delete(java.lang.String file)
@Deprecated public static void delete(File... files)
@Deprecated public static void deleteRecursiveWithThrottle(File dir, com.google.common.util.concurrent.RateLimiter rateLimiter)
dir
- Directory to be deletedFSWriteError
- if any part of the tree cannot be deleted@Deprecated public static void deleteRecursive(File dir)
dir
- Directory to be deletedFSWriteError
- if any part of the tree cannot be deleted@Deprecated public static void deleteRecursiveOnExit(File dir)
dir
- Directory to be deleted@Deprecated public static boolean isSubDirectory(File parent, File child)
@Deprecated public static java.lang.Throwable deleteWithConfirm(File file, java.lang.Throwable accumulate)
@Deprecated public static java.lang.Throwable deleteWithConfirm(File file, java.lang.Throwable accumulate, com.google.common.util.concurrent.RateLimiter rateLimiter)
@Deprecated public static void deleteWithConfirm(java.lang.String file)
@Deprecated public static void deleteWithConfirm(File file)
@Deprecated public static void renameWithOutConfirm(java.lang.String from, java.lang.String to)
@Deprecated public static void renameWithConfirm(java.lang.String from, java.lang.String to)
public static void moveRecursively(java.nio.file.Path source, java.nio.file.Path target) throws java.io.IOException
Once a file has been copied to the target directory it will be deleted from the source directory. If a file already exists in the target directory a warning will be logged and the file will not be deleted.
source
- the directory containing the files to movetarget
- the directory where the files must be movedjava.io.IOException
public static void deleteDirectoryIfEmpty(java.nio.file.Path path) throws java.io.IOException
path
- the path to the directoryjava.io.IOException
Copyright © 2009-2022 The Apache Software Foundation