Spec-Zone .ru
спецификации, руководства, описания, API
|
|
Java™ Platform Standard Ed. 7 DRAFT ea-b118 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface FileRef
A reference to a file.
A FileRef
is an object that locates a file and defines methods to
open the file for reading or writing. It also provides access to associated
metadata or file attributes.
Attributes
,
File.toPath()
Modifier and Type | Method and Description | |
---|---|---|
Object |
getAttribute(String attribute,
LinkOption... options)
Reads the value of a file attribute. |
|
|
getFileAttributeView(Class<V> type,
LinkOption... options)
Returns a file attribute view of a given type. |
|
InputStream |
newInputStream(OpenOption... options)
Opens the file referenced by this object, returning an input stream to read from the file. |
|
OutputStream |
newOutputStream(OpenOption... options)
Opens or creates the file located by this object for writing, returning an output stream to write bytes to the file. |
|
Map<String,?> |
readAttributes(String attributes,
LinkOption... options)
Reads a set of file attributes as a bulk operation. |
|
void |
setAttribute(String attribute,
Object value,
LinkOption... options)
Sets the value of a file attribute. |
Method Detail |
---|
InputStream newInputStream(OpenOption... options) throws IOException
mark
or reset
methods. The stream will be safe for access by multiple concurrent
threads. Reading commences at the beginning of the file.
The options
parameter determines how the file is opened.
If no options are present then it is equivalent to opening the file with
the READ
option. In addition to the READ
option, an implementation may also support additional implementation
specific options.
IllegalArgumentException
- if an invalid combination of options is specifiedUnsupportedOperationException
- if an unsupported option is specifiedIOException
- if an I/O error occursSecurityException
- In the case of the default provider, and a security manager is
installed, the checkRead
method is invoked to check read access to the file.OutputStream newOutputStream(OpenOption... options) throws IOException
The options
parameter determines how the file is opened.
If no options are present then this method creates a new file for writing
or truncates an existing file. In addition to the standard
options, an implementation may also support additional
implementation specific options.
The resulting stream will not be buffered. The stream will be safe for access by multiple concurrent threads.
options
- options specifying how the file is openedIllegalArgumentException
- if options
contains an invalid combination of optionsUnsupportedOperationException
- if an unsupported option is specifiedIOException
- if an I/O error occursSecurityException
- In the case of the default provider, and a security manager is
installed, the checkWrite
method is invoked to check write access to the file.<V extends FileAttributeView> V getFileAttributeView(Class<V> type, LinkOption... options)
A file attribute view provides a read-only or updatable view of a
set of file attributes. This method is intended to be used where the file
attribute view defines type-safe methods to read or update the file
attributes. The type
parameter is the type of the attribute view
required and the method returns an instance of that type if supported.
The BasicFileAttributeView
type supports access to the basic
attributes of a file. Invoking this method to select a file attribute
view of that type will always return an instance of that class.
The options
array may be used to indicate how symbolic links
are handled by the resulting file attribute view for the case that the
file is a symbolic link. By default, symbolic links are followed. If the
option NOFOLLOW_LINKS
is present then
symbolic links are not followed. This option is ignored by implementations
that do not support symbolic links.
type
- the Class
object corresponding to the file attribute viewoptions
- options indicating how symbolic links are handlednull
if
the attribute view type is not availableUnsupportedOperationException
- If options contains an unsupported option. This exception is
specified to allow the LinkOption
enum be extended
in future releases.Attributes.readBasicFileAttributes(java.nio.file.FileRef, java.nio.file.LinkOption...)
void setAttribute(String attribute, Object value, LinkOption... options) throws IOException
The attribute
parameter identifies the attribute to be set
and takes the form:
[view-name:]attribute-namewhere square brackets [...] delineate an optional component and the character
':'
stands for itself.
view-name is the name
of a FileAttributeView
that identifies a set of file attributes. If not
specified then it defaults to "basic"
, the name of the file
attribute view that identifies the basic set of file attributes common to
many file systems. attribute-name is the name of the attribute
within the set.
Usage Example: Suppose we want to set the DOS "hidden" attribute:
file.setAttribute("dos:hidden", true);
attribute
- the attribute to setvalue
- the attribute valueoptions
- options indicating how symbolic links are handledUnsupportedOperationException
- if the attribute view is not available or it does not support
updating the attributeIllegalArgumentException
- if the attribute value is of the correct type but has an
inappropriate valueClassCastException
- If the attribute value is not of the expected type or is a
collection containing elements that are not of the expected
typeIOException
- If an I/O error occursSecurityException
- In the case of the default provider, and a security manager is
installed, its checkWrite
method denies write access to the file. If this method is invoked
to set security sensitive attributes then the security manager
may be invoked to check for additional permissions.Object getAttribute(String attribute, LinkOption... options) throws IOException
The attribute
parameter identifies the attribute to be read
and takes the form:
[view-name:]attribute-namewhere square brackets [...] delineate an optional component and the character
':'
stands for itself.
view-name is the name
of a FileAttributeView
that identifies a set of file attributes. If not
specified then it defaults to "basic"
, the name of the file
attribute view that identifies the basic set of file attributes common to
many file systems. attribute-name is the name of the attribute.
The options
array may be used to indicate how symbolic links
are handled for the case that the file is a symbolic link. By default,
symbolic links are followed and the file attribute of the final target
of the link is read. If the option NOFOLLOW_LINKS
is present then symbolic links are not followed and so
the method returns the file attribute of the symbolic link.
Usage Example:
Suppose we require the user ID of the file owner on a system that
supports a "unix
" view:
int uid = (Integer)file.getAttribute("unix:uid");
attribute
- the attribute to readoptions
- options indicating how symbolic links are handlednull
if the attribute view
is not available or it does not support reading the attribute
reading the attributeIOException
- if an I/O error occursSecurityException
- In the case of the default provider, and a security manager is
installed, its checkRead
method denies read access to the file. If this method is invoked
to read security sensitive attributes then the security manager
may be invoked to check for additional permissions.Map<String,?> readAttributes(String attributes, LinkOption... options) throws IOException
The attributes
parameter identifies the attributes to be read
and takes the form:
[view-name:]attribute-listwhere square brackets [...] delineate an optional component and the character
':'
stands for itself.
view-name is the name
of a FileAttributeView
that identifies a set of file attributes. If not
specified then it defaults to "basic"
, the name of the file
attribute view that identifies the basic set of file attributes common to
many file systems.
The attribute-list component is a comma separated list of
zero or more names of attributes to read. If the list contains the value
"*"
then all attributes are read. Attributes that are not supported
are ignored and will not be present in the returned map. It is
implementation specific if all attributes are read as an atomic operation
with respect to other file system operations.
The following examples demonstrate possible values for the attributes
parameter:
"*"
Read all basic-file-attributes
."size,lastModifiedTime,lastAccessTime"
Reads the file size, last modified time, and last access time attributes. "posix:*"
Read all POSIX-file-attributes
.."posix:permissions,owner,size"
Reads the POSX file permissions, owner, and file size.
The options
array may be used to indicate how symbolic links
are handled for the case that the file is a symbolic link. By default,
symbolic links are followed and the file attribute of the final target
of the link is read. If the option NOFOLLOW_LINKS
is present then symbolic links are not followed and so
the method returns the file attribute of the symbolic link.
attributes
- The attributes to readoptions
- Options indicating how symbolic links are handledIOException
- If an I/O error occursSecurityException
- In the case of the default provider, and a security manager is
installed, its checkRead
method denies read access to the file. If this method is invoked
to read security sensitive attributes then the security manager
may be invoke to check for additional permissions.
|
Java™ Platform Standard Ed. 7 DRAFT ea-b118 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright © 1993, 2010, Oracle Corporation. All rights reserved.