Java Reference
In-Depth Information
public class PathMatching {
public static void main(String[] args) {
String globPattern = "glob:**txt";
PathMatcher matcher =
FileSystems.getDefault().getPathMatcher(globPattern);
Path path = Paths.get("C:\\poems\\luci1.txt");
boolean matched = matcher.matches(path);
System.out.format("%s matches %s: %b%n",
globPattern, path, matched);
}
}
glob:**txt matches C:\poems\luci1.txt: true
Managing File Attributes
Through the File class, the java.io API provides support for accessing very basic file attributes such as the last
modified time of a file. NIO.2 has extensive support for managing (reading and writing) the file attributes across
platforms. The java.nio.attribute package contains the attribute-related classes. It bundles the file attributes in the
following six types of views.
1. BasicFileAttributeView : This attribute view allows you to manage the basic file
attributes such as creation time, last access time, last modified time, size, file type (regular
file, directory, symbolic link, or other), and file key (a unique number for a file). It lets you
modify the creation time, the last accessed time, and the last modified time of a file. This
view is supported on all platforms.
2. DosFileAttributeView : It extends the BasicFileAttributeView . As the name suggests,
it allows you to access the file attributes that are specific to DOS. It provides the support
to check if a file is a hidden file, a system file, an archive file, and a read-only file. It is
available only on the systems that support DOS such as Microsoft Windows.
3. PosixFileAttributeView : POSIX stands for Portable Operating System Interface for
UNIX. It extends the BasicFileAttributeView and adds support for attributes that are
available on the systems that support POSIX standards such as UNIX. Apart from basic file
attributes, it lets you manage owner, group, and [related access] permissions.
4. FileOwnerAttributeView : This attribute view lets you manage the owner of a file.
5. AclFileAttributeView : ACL stands for Access Control List. It is a list of permissions
attached to a file. It lets you manage the ACL for a file.
6. UserDefinedFileAttributeView : This view lets you manage a set of user-defined
attributes for a file in the form of name-value pairs. Sometimes the user-defined attributes
of a file are also known as extended attributes . The name of an attribute is a String . The
value of an attribute could be of any data type.
Some attribute views are available across platforms and some only on specific platforms. An implementation
may provide additional file attribute views.
 
Search WWH ::




Custom Search