public class FileUtils extends Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
FileUtils.FileOperation |
static interface |
FileUtils.LineListener |
static class |
FileUtils.MaybeWindowsMemoryMappedFileReleaseProblem |
| Constructor and Description |
|---|
FileUtils() |
| Modifier and Type | Method and Description |
|---|---|
static OpenOption[] |
convertOpenMode(String mode) |
static void |
copyFile(File srcFile,
File dstFile) |
static void |
copyRecursively(File fromDirectory,
File toDirectory) |
static void |
copyRecursively(File fromDirectory,
File toDirectory,
FileFilter filter) |
static boolean |
deleteFile(File file) |
static void |
deletePathRecursively(Path path) |
static void |
deleteRecursively(File directory) |
static FileUtils.LineListener |
echo(PrintStream target) |
static String |
fixSeparatorsInPath(String path) |
static File |
getMostCanonicalFile(File file) |
static boolean |
isEmptyDirectory(File directory)
Check if directory is empty.
|
static void |
moveFile(File toMove,
File target)
Utility method that moves a file from its current location to the
new target location.
|
static File |
moveFileToDirectory(File toMove,
File targetDirectory)
Utility method that moves a file from its current location to the
provided target directory.
|
static BufferedReader |
newBufferedFileReader(File file,
Charset charset) |
static PrintWriter |
newFilePrintWriter(File file,
Charset charset) |
static FileChannel |
open(Path path,
String mode) |
static InputStream |
openAsInputStream(Path path) |
static OutputStream |
openAsOutputStream(Path path,
boolean append) |
static File |
path(File root,
String... path) |
static File |
path(String root,
String... path) |
static File |
pathToFileAfterMove(File fromDir,
File toDir,
File fileToMove)
Useful when you want to move a file from one directory to another by renaming the file
and keep eventual sub directories.
|
static Path |
pathToFileAfterMove(Path fromDir,
Path toDir,
Path fileToMove)
Resolve toDir against fileToMove relativized against fromDir, resulting in a path denoting the location of
fileToMove after being moved fromDir toDir.
|
static String |
readTextFile(File file,
Charset charset) |
static void |
readTextFile(File file,
FileUtils.LineListener listener) |
static String |
relativePath(File baseDir,
File storeFile)
Given a directory and a path under it, return filename of the path
relative to the directory.
|
static void |
renameFile(File srcFile,
File renameToFile,
CopyOption... copyOptions) |
static void |
truncateFile(File file,
long position) |
static void |
truncateFile(SeekableByteChannel fileChannel,
long position) |
static void |
windowsSafeIOOperation(FileUtils.FileOperation operation) |
static void |
writeAll(FileChannel channel,
ByteBuffer src) |
static void |
writeAll(FileChannel channel,
ByteBuffer src,
long position) |
static void |
writeToFile(File target,
String text,
boolean append) |
public static void deleteRecursively(File directory) throws IOException
IOExceptionpublic static void deletePathRecursively(Path path) throws IOException
IOExceptionpublic static boolean deleteFile(File file)
public static void moveFile(File toMove, File target) throws IOException
renameFile(File, File, CopyOption...) instead.toMove - The File object to move.target - Target file to move to.IOExceptionpublic static File moveFileToDirectory(File toMove, File targetDirectory) throws IOException
renameFile(File, File, CopyOption...) instead.toMove - The File object to move.targetDirectory - the destination directoryIOExceptionpublic static void renameFile(File srcFile, File renameToFile, CopyOption... copyOptions) throws IOException
IOExceptionpublic static void truncateFile(SeekableByteChannel fileChannel, long position) throws IOException
IOExceptionpublic static void truncateFile(File file, long position) throws IOException
IOExceptionpublic static void copyFile(File srcFile, File dstFile) throws IOException
IOExceptionpublic static void copyRecursively(File fromDirectory, File toDirectory) throws IOException
IOExceptionpublic static void copyRecursively(File fromDirectory, File toDirectory, FileFilter filter) throws IOException
IOExceptionpublic static void writeToFile(File target, String text, boolean append) throws IOException
IOExceptionpublic static BufferedReader newBufferedFileReader(File file, Charset charset) throws FileNotFoundException
FileNotFoundExceptionpublic static PrintWriter newFilePrintWriter(File file, Charset charset) throws FileNotFoundException
FileNotFoundExceptionpublic static File pathToFileAfterMove(File fromDir, File toDir, File fileToMove)
You want to move file /a/b1/c/d/file from /a/b1 to /a/b2 and keep the sub path /c/d/file.
fileToMove = new File( "/a/b1/c/d/file" );
fromDir = new File( "/a/b1" );
toDir = new File( "/a/b2" );
fileToMove.rename( pathToFileAfterMove( fromDir, toDir, fileToMove ) );
// fileToMove.getAbsolutePath() -> /a/b2/c/d/file
Calls pathToFileAfterMove(Path, Path, Path) after
transforming given files to paths by calling File.toPath().
NOTE: This that this does not perform the move, it only calculates the new file name.
Throws IllegalArgumentException is fileToMove is not a sub path to fromDir.
fromDir - Current parent directory for fileToMovetoDir - Directory denoting new parent directory for fileToMove after movefileToMove - File denoting current location for fileToMoveFile denoting new abstract path for file after move.public static Path pathToFileAfterMove(Path fromDir, Path toDir, Path fileToMove)
NOTE: This that this does not perform the move, it only calculates the new file name.
Throws IllegalArgumentException is fileToMove is not a sub path to fromDir.
fromDir - Path denoting current parent directory for fileToMovetoDir - Path denoting location for fileToMove after movefileToMove - Path denoting current location for fileToMovePath denoting new abstract path for file after move.public static void windowsSafeIOOperation(FileUtils.FileOperation operation) throws IOException
IOExceptionpublic static FileUtils.LineListener echo(PrintStream target)
public static void readTextFile(File file, FileUtils.LineListener listener) throws IOException
IOExceptionpublic static String readTextFile(File file, Charset charset) throws IOException
IOExceptionpublic static String relativePath(File baseDir, File storeFile) throws IOException
baseDir - The base directory, containing the storeFilestoreFile - The store file path, must be contained under
baseDirstoreFile to
baseDirIOException - As per File.getCanonicalPath()public static void writeAll(FileChannel channel, ByteBuffer src, long position) throws IOException
IOExceptionpublic static void writeAll(FileChannel channel, ByteBuffer src) throws IOException
IOExceptionpublic static OpenOption[] convertOpenMode(String mode)
public static FileChannel open(Path path, String mode) throws IOException
IOExceptionpublic static InputStream openAsInputStream(Path path) throws IOException
IOExceptionpublic static boolean isEmptyDirectory(File directory) throws IOException
directory - - directory to checkIllegalArgumentException - if specified directory represent a fileIOException - if some problem encountered during reading directory contentpublic static OutputStream openAsOutputStream(Path path, boolean append) throws IOException
IOExceptionCopyright © 2002–2017 The Neo4j Graph Database Project. All rights reserved.