Java DosFileAttributes check if file is archive, hidden, read only and system file

Description

Java DosFileAttributes check if file is archive, hidden, read only and system file

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.LinkOption;
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) throws IOException {
    Path pWin = Paths.get("C:\\tmp\\file1.txt");
    DosFileAttributes fa = Files.readAttributes(pWin, DosFileAttributes.class, LinkOption.NOFOLLOW_LINKS);

    // Dos specific, uncomment if you're in Windows
    System.out.println("Is archive? " + fa.isArchive());
    System.out.println("Is hidden? " + fa.isHidden());
    System.out.println("Is read only? " + fa.isReadOnly());
    System.out.println("Is system? " + fa.isSystem());
  }//from  ww w.  jav  a2  s. c  o m
}



PreviousNext

Related