是否可以使用java修改目录权限,以便任何人都无法访问该目录中的内容。
答案 0 :(得分:2)
您可以在File
对象上使用此方法
boolean setWritable(boolean writable, boolean ownerOnly)
boolean setReadable(boolean readable, boolean ownerOnly)
boolean setExecutable(boolean executable,boolean ownerOnly)
File dir = new File("my directory");
dir.mkdir();
// Make it not readable, writable and executable for anyone
dir.setExecutable(false, false);
dir.setReadable(false, false);
dir.setWritable(false, false);
// Make it readable, writable and executable for the owner only (see
// second parameter "ownerOnly" to these calls)
dir.setExecutable(true, true);
dir.setReadable(true, true);
dir.setWritable(true, true);
Java NIO API具有更多细粒度控件来执行相同操作,例如