How to list only non hidden and non system file in jtree

后端 未结 3 1337
栀梦
栀梦 2021-01-20 16:51
File f=new File(\"C:/\");
File fList[] = f.listFiles();

When i use this it list all system file as well as hidden files.

and this cause

3条回答
  •  别那么骄傲
    2021-01-20 17:27

    If running under Windows, Java 7 introduced DosFileAttributes which enables system and hidden files to be filtered. This can be used in conjunction with a FileFilter

    Path srcFile = Paths.get("myDirectory");
    DosFileAttributes dfa = Files.readAttributes(srcFile, DosFileAttributes.class);
    System.out.println("System File? " + dfa.isSystem());
    System.out.println("Hidden File? " + dfa.isHidden());
    

提交回复
热议问题