FilePath

A path to a file. It similar to the Java 7 java.nio.file.Path, but simpler, and works with older versions of Java. It also implements the relevant methods found in java.nio.file.FileSystem and FileSystems

Methods
static FilePath get(String path)
Get the file path object for the given path.
static FilePath get(String path)
Get the file path object for the given path. Windows-style '\' is replaced with '/'.
Parameters:
path - the path
Returns:
the file path object
static String getNextTempFileNamePart(boolean newRandom)
Get the next temporary file name part (the part in the middle).
static String getNextTempFileNamePart(boolean newRandom)
Get the next temporary file name part (the part in the middle).
Parameters:
newRandom - if the random part of the filename should change
Returns:
the file name part
static void register(FilePath provider)
Register a file provider.
static void register(FilePath provider)
Register a file provider.
Parameters:
provider - the file provider
static void unregister(FilePath provider)
Unregister a file provider.
static void unregister(FilePath provider)
Unregister a file provider.
Parameters:
provider - the file provider
boolean canWrite()
Check if the file is writable.
boolean canWrite()
Check if the file is writable.
Returns:
if the file is writable
void createDirectory()
Create a directory (all required parent directories already exist).
void createDirectory()
Create a directory (all required parent directories already exist).
boolean createFile()
Create a new file.
boolean createFile()
Create a new file.
Returns:
true if creating was successful
FilePath createTempFile(String suffix, boolean deleteOnExit, boolean inTempDir)
Create a new temporary file.
FilePath createTempFile(String suffix, boolean deleteOnExit, boolean inTempDir) throws IOException
Create a new temporary file.
Parameters:
suffix - the suffix
deleteOnExit - if the file should be deleted when the virtual machine exists
inTempDir - if the file should be stored in the temporary directory
Returns:
the name of the created file
void delete()
Delete a file or directory if it exists.
void delete()
Delete a file or directory if it exists. Directories may only be deleted if they are empty.
boolean exists()
Checks if a file exists.
boolean exists()
Checks if a file exists.
Returns:
true if it exists
String getName()
Get the file or directory name (the last element of the path).
String getName()
Get the file or directory name (the last element of the path).
Returns:
the last element of the path
FilePath getParent()
Get the parent directory of a file or directory.
FilePath getParent()
Get the parent directory of a file or directory.
Returns:
the parent directory name
FilePath getPath(String path)
Convert a file to a path.
FilePath getPath(String path)
Convert a file to a path. This is similar to java.nio.file.spi.FileSystemProvider.getPath, but may return an object even if the scheme doesn't match in case of the the default file provider.
Parameters:
path - the path
Returns:
the file path object
String getScheme()
Get the scheme (prefix) for this file provider.
String getScheme()
Get the scheme (prefix) for this file provider. This is similar to java.nio.file.spi.FileSystemProvider.getScheme.
Returns:
the scheme
boolean isAbsolute()
Check if the file name includes a path.
boolean isAbsolute()
Check if the file name includes a path.
Returns:
if the file name is absolute
boolean isDirectory()
Check if it is a file or a directory.
boolean isDirectory()
Check if it is a file or a directory.
Returns:
true if it is a directory
long lastModified()
Get the last modified date of a file
long lastModified()
Get the last modified date of a file
Returns:
the last modified date
void moveTo(FilePath newName, boolean atomicReplace)
Rename a file if this is allowed.
void moveTo(FilePath newName, boolean atomicReplace)
Rename a file if this is allowed.
Parameters:
newName - the new fully qualified file name
atomicReplace - whether the move should be atomic, and the target file should be replaced if it exists and replacing is possible
List newDirectoryStream()
List the files and directories in the given directory.
List newDirectoryStream()
List the files and directories in the given directory.
Returns:
the list of fully qualified file names
InputStream newInputStream()
Create an input stream to read from the file.
InputStream newInputStream() throws IOException
Create an input stream to read from the file.
Returns:
the input stream
OutputStream newOutputStream(boolean append)
Create an output stream to write into the file.
OutputStream newOutputStream(boolean append) throws IOException
Create an output stream to write into the file.
Parameters:
append - if true, the file will grow, if false, the file will be truncated first
Returns:
the output stream
FileChannel open(String mode)
Open a random access file object.
FileChannel open(String mode) throws IOException
Open a random access file object.
Parameters:
mode - the access mode. Supported are r, rw, rws, rwd
Returns:
the file object
boolean setReadOnly()
Disable the ability to write.
boolean setReadOnly()
Disable the ability to write.
Returns:
true if the call was successful
long size()
Get the size of a file in bytes
long size()
Get the size of a file in bytes
Returns:
the size in bytes
FilePath toRealPath()
Normalize a file name.
FilePath toRealPath()
Normalize a file name.
Returns:
the normalized file name
String toString()
Get the string representation.
String toString()
Get the string representation. The returned string can be used to construct a new object.
Returns:
the path as a string
FilePath unwrap()
Get the unwrapped file name (without wrapper prefixes if wrapping / delegating file systems are used).
FilePath unwrap()
Get the unwrapped file name (without wrapper prefixes if wrapping / delegating file systems are used).
Returns:
the unwrapped path

Fields
static String name

name

The complete path (which may be absolute or relative, depending on the file system).