BasicFileAttributes
Stay organized with collections
Save and categorize content based on your preferences.
Known Indirect Subclasses
DosFileAttributes |
File attributes associated with a file in a file system that supports
legacy "DOS" attributes. |
PosixFileAttributes |
File attributes associated with files on file systems used by operating systems
that implement the Portable Operating System Interface (POSIX) family of
standards. |
|
Basic attributes associated with a file in a file system.
Basic file attributes are attributes that are common to many file systems
and consist of mandatory and optional file attributes as defined by this
interface.
Usage Example:
Path file = ...
BasicFileAttributes attrs = Files.readAttributes(file, BasicFileAttributes.class);
Public Method Summary
abstract
FileTime
|
|
abstract
Object
|
fileKey()
Returns an object that uniquely identifies the given file, or null if a file key is not available.
|
abstract
boolean
|
|
abstract
boolean
|
isOther()
Tells whether the file is something other than a regular file, directory,
or symbolic link.
|
abstract
boolean
|
isRegularFile()
Tells whether the file is a regular file with opaque content.
|
abstract
boolean
|
|
abstract
FileTime
|
|
abstract
FileTime
|
|
abstract
long
|
size()
Returns the size of the file (in bytes).
|
Public Methods
public
abstract
FileTime
creationTime
()
Returns the creation time. The creation time is the time that the file
was created.
If the file system implementation does not support a time stamp
to indicate the time when the file was created then this method returns
an implementation specific default value, typically the last-modified-time
or a FileTime
representing the epoch (1970-01-01T00:00:00Z).
Returns
- a
FileTime
representing the time the file was created
public
abstract
Object
fileKey
()
Returns an object that uniquely identifies the given file, or null
if a file key is not available. On some platforms or file systems
it is possible to use an identifier, or a combination of identifiers to
uniquely identify a file. Such identifiers are important for operations
such as file tree traversal in file systems that support symbolic links or file systems
that allow a file to be an entry in more than one directory. On UNIX file
systems, for example, the device ID and inode are
commonly used for such purposes.
The file key returned by this method can only be guaranteed to be
unique if the file system and files remain static. Whether a file system
re-uses identifiers after a file is deleted is implementation dependent and
therefore unspecified.
File keys returned by this method can be compared for equality and are
suitable for use in collections. If the file system and files remain static,
and two files are the same
with
non-null
file keys, then their file keys are equal.
Returns
- an object that uniquely identifies the given file, or
null
public
abstract
boolean
isDirectory
()
Tells whether the file is a directory.
Returns
true
if the file is a directory
public
abstract
boolean
isOther
()
Tells whether the file is something other than a regular file, directory,
or symbolic link.
Returns
true
if the file something other than a regular file,
directory or symbolic link
public
abstract
boolean
isRegularFile
()
Tells whether the file is a regular file with opaque content.
Returns
true
if the file is a regular file with opaque content
public
abstract
boolean
isSymbolicLink
()
Tells whether the file is a symbolic link.
Returns
true
if the file is a symbolic link
public
abstract
FileTime
lastAccessTime
()
Returns the time of last access.
If the file system implementation does not support a time stamp
to indicate the time of last access then this method returns
an implementation specific default value, typically the last-modified-time
or a FileTime
representing the epoch (1970-01-01T00:00:00Z).
Returns
- a
FileTime
representing the time of last access
public
abstract
FileTime
lastModifiedTime
()
Returns the time of last modification.
If the file system implementation does not support a time stamp
to indicate the time of last modification then this method returns an
implementation specific default value, typically a FileTime
representing the epoch (1970-01-01T00:00:00Z).
Returns
- a
FileTime
representing the time the file was last
modified
public
abstract
long
size
()
Returns the size of the file (in bytes). The size may differ from the
actual size on the file system due to compression, support for sparse
files, or other reasons. The size of files that are not regular
files is implementation specific and
therefore unspecified.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["\u003cp\u003e\u003ccode\u003eBasicFileAttributes\u003c/code\u003e provides essential file attributes like creation time, last access time, last modified time, and size.\u003c/p\u003e\n"],["\u003cp\u003eIt can identify if a file is a directory, regular file, symbolic link, or other type.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003efileKey()\u003c/code\u003e method offers a unique identifier for a file within a static file system.\u003c/p\u003e\n"],["\u003cp\u003eThis interface is commonly used with \u003ccode\u003eFiles.readAttributes()\u003c/code\u003e to retrieve file attributes.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eDosFileAttributes\u003c/code\u003e and \u003ccode\u003ePosixFileAttributes\u003c/code\u003e extend this interface for platform-specific attributes.\u003c/p\u003e\n"]]],["`BasicFileAttributes` is an interface detailing common file system attributes. Key actions include retrieving: the file's `creationTime`, `lastAccessTime`, `lastModifiedTime`, and `size`. It also provides methods to check if a file `isDirectory`, `isRegularFile`, `isSymbolicLink`, or `isOther`, as well as a unique `fileKey` if available. The `DosFileAttributes` and `PosixFileAttributes` are indirect subclasses, which are used to deal with the specificities of their respective file system.\n"],null,["# BasicFileAttributes\n\npublic interface **BasicFileAttributes** \n\n|---|---|---|\n| Known Indirect Subclasses [DosFileAttributes](../../../../../reference/java/nio/file/attribute/DosFileAttributes.html), [PosixFileAttributes](../../../../../reference/java/nio/file/attribute/PosixFileAttributes.html) |--------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [DosFileAttributes](../../../../../reference/java/nio/file/attribute/DosFileAttributes.html) | File attributes associated with a file in a file system that supports legacy \"DOS\" attributes. | | [PosixFileAttributes](../../../../../reference/java/nio/file/attribute/PosixFileAttributes.html) | File attributes associated with files on file systems used by operating systems that implement the Portable Operating System Interface (POSIX) family of standards. | |||\n\nBasic attributes associated with a file in a file system.\n\nBasic file attributes are attributes that are common to many file systems\nand consist of mandatory and optional file attributes as defined by this\ninterface.\n\n**Usage Example:** \n\n```\n Path file = ...\n BasicFileAttributes attrs = Files.readAttributes(file, BasicFileAttributes.class);\n \n```\n\n\u003cbr /\u003e\n\n##### See Also\n\n- [BasicFileAttributeView](../../../../../reference/java/nio/file/attribute/BasicFileAttributeView.html) \n\n### Public Method Summary\n\n|-------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract FileTime | [creationTime](../../../../../reference/java/nio/file/attribute/BasicFileAttributes.html#creationTime())() Returns the creation time. |\n| abstract [Object](../../../../../reference/java/lang/Object.html) | [fileKey](../../../../../reference/java/nio/file/attribute/BasicFileAttributes.html#fileKey())() Returns an object that uniquely identifies the given file, or `null` if a file key is not available. |\n| abstract boolean | [isDirectory](../../../../../reference/java/nio/file/attribute/BasicFileAttributes.html#isDirectory())() Tells whether the file is a directory. |\n| abstract boolean | [isOther](../../../../../reference/java/nio/file/attribute/BasicFileAttributes.html#isOther())() Tells whether the file is something other than a regular file, directory, or symbolic link. |\n| abstract boolean | [isRegularFile](../../../../../reference/java/nio/file/attribute/BasicFileAttributes.html#isRegularFile())() Tells whether the file is a regular file with opaque content. |\n| abstract boolean | [isSymbolicLink](../../../../../reference/java/nio/file/attribute/BasicFileAttributes.html#isSymbolicLink())() Tells whether the file is a symbolic link. |\n| abstract FileTime | [lastAccessTime](../../../../../reference/java/nio/file/attribute/BasicFileAttributes.html#lastAccessTime())() Returns the time of last access. |\n| abstract FileTime | [lastModifiedTime](../../../../../reference/java/nio/file/attribute/BasicFileAttributes.html#lastModifiedTime())() Returns the time of last modification. |\n| abstract long | [size](../../../../../reference/java/nio/file/attribute/BasicFileAttributes.html#size())() Returns the size of the file (in bytes). |\n\nPublic Methods\n--------------\n\n#### public abstract FileTime\n**creationTime**\n()\n\nReturns the creation time. The creation time is the time that the file\nwas created.\n\nIf the file system implementation does not support a time stamp\nto indicate the time when the file was created then this method returns\nan implementation specific default value, typically the [last-modified-time](../../../../../reference/java/nio/file/attribute/BasicFileAttributes.html#lastModifiedTime()) or a `FileTime`\nrepresenting the epoch (1970-01-01T00:00:00Z). \n\n##### Returns\n\n- a `FileTime` representing the time the file was created \n\n#### public abstract [Object](../../../../../reference/java/lang/Object.html)\n**fileKey**\n()\n\nReturns an object that uniquely identifies the given file, or `null` if a file key is not available. On some platforms or file systems\nit is possible to use an identifier, or a combination of identifiers to\nuniquely identify a file. Such identifiers are important for operations\nsuch as file tree traversal in file systems that support [symbolic links](../package-summary.html#links) or file systems\nthat allow a file to be an entry in more than one directory. On UNIX file\nsystems, for example, the *device ID* and *inode* are\ncommonly used for such purposes.\n\nThe file key returned by this method can only be guaranteed to be\nunique if the file system and files remain static. Whether a file system\nre-uses identifiers after a file is deleted is implementation dependent and\ntherefore unspecified.\n\nFile keys returned by this method can be compared for equality and are\nsuitable for use in collections. If the file system and files remain static,\nand two files are the [same](../../../../../reference/java/nio/file/Files.html#isSameFile(java.nio.file.Path,%20java.nio.file.Path)) with\nnon-`null` file keys, then their file keys are equal. \n\n##### Returns\n\n- an object that uniquely identifies the given file, or `null` \n\n##### See Also\n\n- [Files.walkFileTree(Path, FileVisitor)](../../../../../reference/java/nio/file/Files.html#walkFileTree(java.nio.file.Path,%20java.nio.file.FileVisitor\u003c?%20super%20java.nio.file.Path\u003e)) \n\n#### public abstract boolean\n**isDirectory**\n()\n\nTells whether the file is a directory. \n\n##### Returns\n\n- `true` if the file is a directory \n\n#### public abstract boolean\n**isOther**\n()\n\nTells whether the file is something other than a regular file, directory,\nor symbolic link. \n\n##### Returns\n\n- `true` if the file something other than a regular file, directory or symbolic link \n\n#### public abstract boolean\n**isRegularFile**\n()\n\nTells whether the file is a regular file with opaque content. \n\n##### Returns\n\n- `true` if the file is a regular file with opaque content \n\n#### public abstract boolean\n**isSymbolicLink**\n()\n\nTells whether the file is a symbolic link. \n\n##### Returns\n\n- `true` if the file is a symbolic link \n\n#### public abstract FileTime\n**lastAccessTime**\n()\n\nReturns the time of last access.\n\nIf the file system implementation does not support a time stamp\nto indicate the time of last access then this method returns\nan implementation specific default value, typically the [last-modified-time](../../../../../reference/java/nio/file/attribute/BasicFileAttributes.html#lastModifiedTime()) or a `FileTime`\nrepresenting the epoch (1970-01-01T00:00:00Z). \n\n##### Returns\n\n- a `FileTime` representing the time of last access \n\n#### public abstract FileTime\n**lastModifiedTime**\n()\n\nReturns the time of last modification.\n\nIf the file system implementation does not support a time stamp\nto indicate the time of last modification then this method returns an\nimplementation specific default value, typically a `FileTime`\nrepresenting the epoch (1970-01-01T00:00:00Z). \n\n##### Returns\n\n- a `FileTime` representing the time the file was last modified \n\n#### public abstract long\n**size**\n()\n\nReturns the size of the file (in bytes). The size may differ from the\nactual size on the file system due to compression, support for sparse\nfiles, or other reasons. The size of files that are not [regular](../../../../../reference/java/nio/file/attribute/BasicFileAttributes.html#isRegularFile()) files is implementation specific and\ntherefore unspecified. \n\n##### Returns\n\n- the file size, in bytes"]]