Package | Description |
---|---|
java.nio.channels |
Defines channels, which represent connections to entities that are capable of
performing I/O operations, such as files.
|
java.nio.file |
Defines interfaces and classes for the Java virtual machine to access files,
file attributes, and file systems.
|
Modifier and Type | Method and Description |
---|---|
static FileChannel |
FileChannel.open(Path path,
OpenOption... options)
Opens or creates a file, returning a file channel to access the file.
|
static FileChannel |
FileChannel.open(Path path,
Set<? extends OpenOption> options,
FileAttribute<?>... attrs)
Opens or creates a file, returning a file channel to access the file.
|
Modifier and Type | Method and Description |
---|---|
static Path |
Files.copy(Path source,
Path target,
CopyOption... options)
Copy a file to a target file.
|
static Path |
Files.createDirectories(Path dir,
FileAttribute<?>... attrs)
Creates a directory by creating all nonexistent parent directories first.
|
static Path |
Files.createDirectory(Path dir,
FileAttribute<?>... attrs)
Creates a new directory.
|
static Path |
Files.createFile(Path path,
FileAttribute<?>... attrs)
Creates a new and empty file, failing if the file already exists.
|
static Path |
Files.createTempDirectory(Path dir,
String prefix,
FileAttribute<?>... attrs)
Creates a new directory in the specified directory, using the given
prefix to generate its name.
|
static Path |
Files.createTempDirectory(String prefix,
FileAttribute<?>... attrs)
Creates a new directory in the default temporary-file directory, using
the given prefix to generate its name.
|
static Path |
Files.createTempFile(Path dir,
String prefix,
String suffix,
FileAttribute<?>... attrs)
Creates a new empty file in the specified directory, using the given
prefix and suffix strings to generate its name.
|
static Path |
Files.createTempFile(String prefix,
String suffix,
FileAttribute<?>... attrs)
Creates an empty file in the default temporary-file directory, using
the given prefix and suffix to generate its name.
|
static Path |
Paths.get(String first,
String... more)
Converts a path string, or a sequence of strings that when joined form
a path string, to a
Path . |
Path |
Path.getFileName()
Returns the name of the file or directory denoted by this path as a
Path object. |
Path |
Path.getName(int index)
Returns a name element of this path as a
Path object. |
Path |
Path.getParent()
Returns the parent path, or
null if this path does not
have a parent. |
abstract Path |
FileSystem.getPath(String first,
String... more)
Converts a path string, or a sequence of strings that when joined form
a path string, to a
Path . |
Path |
Path.getRoot()
Returns the root component of this path as a
Path object,
or null if this path does not have a root component. |
static Path |
Files.move(Path source,
Path target,
CopyOption... options)
Move or rename a file to a target file.
|
Path |
Path.normalize()
Returns a path that is this path with redundant name elements eliminated.
|
Path |
Path.relativize(Path other)
Constructs a relative path between this path and a given path.
|
Path |
Path.resolve(Path other)
Resolve the given path against this path.
|
Path |
Path.resolve(String other)
Converts a given path string to a
Path and resolves it against
this Path in exactly the manner specified by the resolve method. |
Path |
Path.resolveSibling(Path other)
Resolves the given path against this path's
parent
path. |
Path |
Path.resolveSibling(String other)
Converts a given path string to a
Path and resolves it against
this path's parent path in exactly the manner
specified by the resolveSibling method. |
static Path |
Files.setAttribute(Path path,
String attribute,
Object value,
LinkOption... options)
Sets the value of a file attribute.
|
static Path |
Files.setLastModifiedTime(Path path,
FileTime time)
Updates a file's last modified time attribute.
|
Path |
Path.subpath(int beginIndex,
int endIndex)
Returns a relative
Path that is a subsequence of the name
elements of this path. |
Path |
Path.toAbsolutePath()
Returns a
Path object representing the absolute path of this
path. |
Path |
Path.toRealPath(LinkOption... options)
Returns the real path of an existing file.
|
Modifier and Type | Method and Description |
---|---|
abstract Iterable<Path> |
FileSystem.getRootDirectories()
Returns an object to iterate over the paths of the root directories.
|
Iterator<Path> |
Path.iterator()
Returns an iterator over the name elements of this path.
|
static DirectoryStream<Path> |
Files.newDirectoryStream(Path dir)
Opens a directory, returning a
DirectoryStream to iterate over
all entries in the directory. |
static DirectoryStream<Path> |
Files.newDirectoryStream(Path dir,
DirectoryStream.Filter<? super Path> filter)
Opens a directory, returning a
DirectoryStream to iterate over
the entries in the directory. |
Modifier and Type | Method and Description |
---|---|
int |
Path.compareTo(Path other)
Compares two abstract paths lexicographically.
|
static Path |
Files.copy(Path source,
Path target,
CopyOption... options)
Copy a file to a target file.
|
static Path |
Files.createDirectories(Path dir,
FileAttribute<?>... attrs)
Creates a directory by creating all nonexistent parent directories first.
|
static Path |
Files.createDirectory(Path dir,
FileAttribute<?>... attrs)
Creates a new directory.
|
static Path |
Files.createFile(Path path,
FileAttribute<?>... attrs)
Creates a new and empty file, failing if the file already exists.
|
static Path |
Files.createTempDirectory(Path dir,
String prefix,
FileAttribute<?>... attrs)
Creates a new directory in the specified directory, using the given
prefix to generate its name.
|
static Path |
Files.createTempFile(Path dir,
String prefix,
String suffix,
FileAttribute<?>... attrs)
Creates a new empty file in the specified directory, using the given
prefix and suffix strings to generate its name.
|
static void |
Files.delete(Path path)
Deletes a file.
|
static boolean |
Files.deleteIfExists(Path path)
Deletes a file if it exists.
|
boolean |
Path.endsWith(Path other)
Tests if this path ends with the given path.
|
static boolean |
Files.exists(Path path,
LinkOption... options)
Tests whether a file exists.
|
static Object |
Files.getAttribute(Path path,
String attribute,
LinkOption... options)
Reads the value of a file attribute.
|
static FileStore |
Files.getFileStore(Path path)
Returns the
FileStore representing the file store where a file
is located. |
static FileTime |
Files.getLastModifiedTime(Path path,
LinkOption... options)
Returns a file's last modified time.
|
static boolean |
Files.isDirectory(Path path,
LinkOption... options)
Tests whether a file is a directory.
|
static boolean |
Files.isHidden(Path path)
Tells whether or not a file is considered hidden.
|
static boolean |
Files.isReadable(Path path)
Tests whether a file is readable.
|
static boolean |
Files.isRegularFile(Path path,
LinkOption... options)
Tests whether a file is a regular file with opaque content.
|
static boolean |
Files.isSameFile(Path path,
Path path2)
Tests if two paths locate the same file.
|
static boolean |
Files.isWritable(Path path)
Tests whether a file is writable.
|
static Path |
Files.move(Path source,
Path target,
CopyOption... options)
Move or rename a file to a target file.
|
static SeekableByteChannel |
Files.newByteChannel(Path path,
OpenOption... options)
Opens or creates a file, returning a seekable byte channel to access the
file.
|
static SeekableByteChannel |
Files.newByteChannel(Path path,
Set<? extends OpenOption> options,
FileAttribute<?>... attrs)
Opens or creates a file, returning a seekable byte channel to access the
file.
|
static DirectoryStream<Path> |
Files.newDirectoryStream(Path dir)
Opens a directory, returning a
DirectoryStream to iterate over
all entries in the directory. |
static DirectoryStream<Path> |
Files.newDirectoryStream(Path dir,
DirectoryStream.Filter<? super Path> filter)
Opens a directory, returning a
DirectoryStream to iterate over
the entries in the directory. |
static InputStream |
Files.newInputStream(Path path,
OpenOption... options)
Opens a file, returning an input stream to read from the file.
|
static OutputStream |
Files.newOutputStream(Path path,
OpenOption... options)
Opens or creates a file, returning an output stream that may be used to
write bytes to the file.
|
static boolean |
Files.notExists(Path path,
LinkOption... options)
Tests whether the file located by this path does not exist.
|
static <A extends BasicFileAttributes> |
Files.readAttributes(Path path,
Class<A> type,
LinkOption... options)
Reads a file's attributes as a bulk operation.
|
Path |
Path.relativize(Path other)
Constructs a relative path between this path and a given path.
|
Path |
Path.resolve(Path other)
Resolve the given path against this path.
|
Path |
Path.resolveSibling(Path other)
Resolves the given path against this path's
parent
path. |
static Path |
Files.setAttribute(Path path,
String attribute,
Object value,
LinkOption... options)
Sets the value of a file attribute.
|
static Path |
Files.setLastModifiedTime(Path path,
FileTime time)
Updates a file's last modified time attribute.
|
static long |
Files.size(Path path)
Returns the size of a file (in bytes).
|
boolean |
Path.startsWith(Path other)
Tests if this path starts with the given path.
|
Modifier and Type | Method and Description |
---|---|
static DirectoryStream<Path> |
Files.newDirectoryStream(Path dir,
DirectoryStream.Filter<? super Path> filter)
Opens a directory, returning a
DirectoryStream to iterate over
the entries in the directory. |
Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. Use of this specification is subject to license terms.