public abstract class FilePath extends Object
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| 限定符和类型 | 字段和说明 |
|---|---|
String |
name
The complete path (which may be absolute or relative, depending on the
file system).
|
| 构造器和说明 |
|---|
FilePath() |
| 限定符和类型 | 方法和说明 |
|---|---|
abstract boolean |
canWrite()
Check if the file is writable.
|
abstract void |
createDirectory()
Create a directory (all required parent directories already exist).
|
abstract boolean |
createFile()
Create a new file.
|
FilePath |
createTempFile(String suffix,
boolean inTempDir)
Create a new temporary file.
|
abstract void |
delete()
Delete a file or directory if it exists.
|
abstract boolean |
exists()
Checks if a file exists.
|
static FilePath |
get(String path)
Get the file path object for the given path.
|
String |
getName()
Get the file or directory name (the last element of the path).
|
abstract FilePath |
getParent()
Get the parent directory of a file or directory.
|
abstract FilePath |
getPath(String path)
Convert a file to a path.
|
abstract String |
getScheme()
Get the scheme (prefix) for this file provider.
|
abstract boolean |
isAbsolute()
Check if the file name includes a path.
|
abstract boolean |
isDirectory()
Check if it is a file or a directory.
|
abstract boolean |
isRegularFile()
Check if it is a regular file.
|
abstract long |
lastModified()
Get the last modified date of a file
|
abstract void |
moveTo(FilePath newName,
boolean atomicReplace)
Rename a file if this is allowed.
|
abstract List<FilePath> |
newDirectoryStream()
List the files and directories in the given directory.
|
static OutputStream |
newFileChannelOutputStream(FileChannel channel,
boolean append)
Create a new output stream from the channel.
|
InputStream |
newInputStream()
Create an input stream to read from the file.
|
OutputStream |
newOutputStream(boolean append)
Create an output stream to write into the file.
|
abstract FileChannel |
open(String mode)
Open a random access file object.
|
static void |
register(FilePath provider)
Register a file provider.
|
abstract boolean |
setReadOnly()
Disable the ability to write.
|
abstract long |
size()
Get the size of a file in bytes
|
abstract FilePath |
toRealPath()
Normalize a file name.
|
String |
toString()
Get the string representation.
|
static void |
unregister(FilePath provider)
Unregister a file provider.
|
FilePath |
unwrap()
Get the unwrapped file name (without wrapper prefixes if wrapping /
delegating file systems are used).
|
public String name
public static FilePath get(String path)
path - the pathpublic static void register(FilePath provider)
provider - the file providerpublic static void unregister(FilePath provider)
provider - the file providerpublic abstract long size()
public abstract void moveTo(FilePath newName, boolean atomicReplace)
newName - the new fully qualified file nameatomicReplace - whether the move should be atomic, and the target
file should be replaced if it exists and replacing is possiblepublic abstract boolean createFile()
public abstract boolean exists()
public abstract void delete()
public abstract List<FilePath> newDirectoryStream()
public abstract FilePath toRealPath()
public abstract FilePath getParent()
public abstract boolean isDirectory()
public abstract boolean isRegularFile()
public abstract boolean isAbsolute()
public abstract long lastModified()
public abstract boolean canWrite()
public abstract void createDirectory()
public String getName()
public OutputStream newOutputStream(boolean append) throws IOException
append - if true, the file will grow, if false, the file will be
truncated firstIOException - If an I/O error occurspublic static final OutputStream newFileChannelOutputStream(FileChannel channel, boolean append) throws IOException
channel - the file channelappend - true for append mode, false for truncate and overwriteIOException - on I/O exceptionpublic abstract FileChannel open(String mode) throws IOException
mode - the access mode. Supported are r, rw, rws, rwdIOException - If an I/O error occurspublic InputStream newInputStream() throws IOException
IOException - If an I/O error occurspublic abstract boolean setReadOnly()
public FilePath createTempFile(String suffix, boolean inTempDir) throws IOException
suffix - the suffixinTempDir - if the file should be stored in the temporary directoryIOException - on failurepublic String toString()
public abstract String getScheme()
java.nio.file.spi.FileSystemProvider.getScheme.public abstract FilePath getPath(String path)
java.nio.file.spi.FileSystemProvider.getPath, but may
return an object even if the scheme doesn't match in case of the
default file provider.path - the pathpublic FilePath unwrap()
Copyright © 2022. All rights reserved.