【发布时间】:2011-08-12 22:51:36
【问题描述】:
我正在尝试创建一个让我隐藏文件的静态方法。 我找到了一些可能的方法,我写了这个:
public static void hide(File src) throws InterruptedException, IOException {
if(System.getProperty("os.name").contains("Windows"))
{
Process p = Runtime.getRuntime().exec("attrib +h " + src.getPath());
p.waitFor();
}
else
{
src.renameTo(new File(src.getParent()+File.separator+"."+src.getName()));
}
}
不幸的是,这在 Windows 和 Ubuntu 上都不起作用... 在 Oracle 的教程中我发现了这种方式
Path file = ...;
Files.setAttribute(file, "dos:hidden", true);
但我不知道如何使用它,因为我的 JDK 没有“Path”类。 谁能帮我提供一种适用于 unix OS 和 Windows 的方法?
【问题讨论】: