jdk/test/java/io/File/IsHidden.java
changeset 5810 e83d67ad8c96
parent 5506 202f599c92aa
child 7668 d4a77089c587
equal deleted inserted replaced
5809:6e38efd0293f 5810:e83d67ad8c96
    25    @bug 4131223 6470354
    25    @bug 4131223 6470354
    26    @summary Basic test for isHidden method
    26    @summary Basic test for isHidden method
    27  */
    27  */
    28 
    28 
    29 import java.io.*;
    29 import java.io.*;
    30 
    30 import java.nio.file.attribute.DosFileAttributeView;
    31 
    31 
    32 public class IsHidden {
    32 public class IsHidden {
    33 
    33 
    34     private static String dir = System.getProperty("test.dir", ".");
    34     private static String dir = System.getProperty("test.dir", ".");
    35 
    35 
    39         if (x != ans)
    39         if (x != ans)
    40             throw new Exception(path + ": expected " + ans + ", got " + x);
    40             throw new Exception(path + ": expected " + ans + ", got " + x);
    41         System.err.println(path + " ==> " + x);
    41         System.err.println(path + " ==> " + x);
    42     }
    42     }
    43 
    43 
       
    44     private static void setHidden(File f, boolean value) throws IOException {
       
    45         f.toPath().getFileAttributeView(DosFileAttributeView.class).setHidden(value);
       
    46     }
       
    47 
    44     private static void testWin32() throws Exception {
    48     private static void testWin32() throws Exception {
    45         File f = new File(dir, "test");
    49         File f = new File(dir, "test");
    46         f.deleteOnExit();
    50         f.deleteOnExit();
    47         f.createNewFile();
    51         f.createNewFile();
    48         String name = f.getCanonicalPath();
    52         setHidden(f, true);
    49         Process p = Runtime.getRuntime().exec("cmd.exe /c attrib +H " + name);
    53         try {
    50         p.waitFor();
    54             ck(f.getPath(), true);
    51         ck(name, true);
    55         } finally {
    52 
    56             setHidden(f, false);
       
    57         }
    53         ck(".foo", false);
    58         ck(".foo", false);
    54         ck("foo", false);
    59         ck("foo", false);
    55     }
    60     }
    56 
    61 
    57     private static void testUnix() throws Exception {
    62     private static void testUnix() throws Exception {