The DosFileAttributeView Interface
As the DosFileAttributeView interface is a subinterface of the BasicFileAttributeView interface, it allows both the basic set of file attributes and the DOS-specific file attributes to be read and updated. Its usage is analogous to the PosixFileAttributeView interface discussed earlier (p. 1336).
interface DosFileAttributeView extends BasicFileAttributeView
String name()
Returns the name of the attribute view, which in this case is the string “dos”.
DosFileAttributes readAttributes()
Reads the basic file attributes as a bulk operation. The DosFileAttributes object can be used to read the values of the basic and DOS-specific file attributes (p. 1333). This method is analogous to the readAttributes() method of the Files class (p. 1328)
void setReadOnly(boolean value)
void setSystem(boolean value)
void setArchive(boolean value)
void setHidden(boolean value)
Update the value of the appropriate attribute. These methods are all implementation specific.
21.7 Creating Directory Entries
The Files class provides methods for creating files and directories. These methods can accept a variable arity parameter of type FileAttribute<?>. The interface java.nio .file.attribute.FileAttribute<T> defines an object that encapsulates the value of a file attribute that can be set when a file or a directory is created by these methods. For a POSIX-based file system, the PosixFilePermissions.asFileAttribute() method creates a FileAttribute that encapsulates a set of type PosixFilePermission (p. 1325).
The methods for creating regular files and directories throw a FileAlreadyExists-Exception if the directory entry with that name already exists. All methods for creating directory entries can throw an IOException, and should be called in a try block or the exception should be specified in a throws clause.
The steps to check whether the directory entry exists and to create the new directory entry if it does not exist are performed as a single atomic operation.
The following code calls the printDirEntryInfo() method in the utility class FileUtils on a path to print what kind of directory entry it denotes and its file permissions.
public static void printDirEntryInfo(Path path) throws IOException {
String fmt = Files.isSymbolicLink(path)? “Symbolic link: %s%n”:
Files.isRegularFile(path)? “File: %s%n”:
Files.isDirectory(path)? “Directory: %s%n”:
“Directory entry: %s%n”;
out.printf(fmt, path);
Set<PosixFilePermission> perms = Files.getPosixFilePermissions(path);
String permStr = PosixFilePermissions.toString(perms);
out.println(permStr);
}
Leave a Reply