0

i want to create hidden folder in java code. i use this code:

   `

    public static void main(String[] args) throws Exception
    { 
        File f=new File(System.getProperty("user.home")+"Desktop/file");
        f.mkdir();
        String cmd="attrib +h "+f.getAbsolutePath(); 
        Runtime.getRuntime().exec(cmd); 
}

`

but the error is:

    `   Exception in thread "main" java.io.IOException: Cannot run program "attrib": error=2, No such file or directory
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1042)
    at java.lang.Runtime.exec(Runtime.java:615)
    at java.lang.Runtime.exec(Runtime.java:448)
    at java.lang.Runtime.exec(Runtime.java:345)
    at filespermssion.testruntime.main(testruntime.java:22)
Caused by: java.io.IOException: error=2, No such file or directory
    at java.lang.UNIXProcess.forkAndExec(Native Method)
    at java.lang.UNIXProcess.<init>(UNIXProcess.java:135)
    at java.lang.ProcessImpl.start(ProcessImpl.java:130)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1023)
    ... 4 more
Java Result: 1`

can you help me

1 Answers1

1

There is a missing / before Desktop, resulting in two directories that mkdir cannot do (mkdirs could have).

File f=new File(System.getProperty("user.home")+"/Desktop/file");
Joop Eggen
  • 107,315
  • 7
  • 83
  • 138
  • i add it but not work the problem is caused by : Cannot run program "attrib": error=2, No such file or directory – user3248198 Mar 25 '14 at 09:45