if(!dataFolder.isHidden())
if(System.getProperty("os.name").toLowerCase()
.indexOf("windows") > -1){
String command = "attrib +h -r -s " + dataFolder.getAbsolutePath();
Runtime.getRuntime().exec(command);
System.out.println(command);
}
我正在运行上面的代码,但我无法让它工作。我想让“.data”文件夹隐藏,不是只读的,也不是系统文件夹,但它被创建为可见且只读。
这是 System.out.println 行的输出:
attrib +h -r -s D:\eclipse\bin\.data
我也无法使用进程的 exitValue() 方法,因为它总是提示:
java.lang.IllegalThreadStateException: process has not exited
我做错了什么?
最佳答案
您应该调用 Process.waitFor()
方法第一。此方法将阻塞,直到 attrib
进程退出。进程在完成之前不会有退出代码。
关于java - 无法使用java的Runtime.getRuntime().exec()隐藏文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7655594/