DOS View Specific to the DOS file system - Java File Path IO

Java examples for File Path IO:DOS File

Introduction

DosFileAttributeView view extends the basic view with the DOS attributes.

There are four attributes, which are mapped by the following methods:

  • isReadOnly(): Returns the readonly attribute's value
  • isHidden(): Returns the hidden attribute's value
  • isArchive(): Returns the archive attribute's value
  • isSystem(): Returns the system attribute's value

The following listing extracts in bulk the preceding four attributes for a given path:

Demo Code

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.DosFileAttributes;

public class Main {
  public static void main(String[] args) {
    DosFileAttributes attr = null;
    Path path = Paths.get("C:/folder1/folder2/folder4", "test.txt");

    try {//from   w  ww .j  ava 2s  .c  o m
        attr = Files.readAttributes(path, DosFileAttributes.class);
    } catch (IOException e) {
        System.err.println(e);
    }
    System.out.println("Is read only ? " + attr.isReadOnly());
    System.out.println("Is Hidden ? " + attr.isHidden());
    System.out.println("Is archive ? " + attr.isArchive());
    System.out.println("Is system ? " + attr.isSystem());

  }
}

Related Tutorials