java - 如何使用 java 阻止用户访问目录?

标签 java security directory file-permissions

是否可以使用java修改目录权限,以便任何人都无法访问该目录内的内容。

最佳答案

您可以使用 File 上的方法此对象

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 有更细粒度的控件来执行相同的操作,例如

关于java - 如何使用 java 阻止用户访问目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40700413/

相关文章:

java - 获取java文件之间的方法调用次数

java - 如何在类路径中递归搜索资源

security - 处理 secret 财务数据时是否有任何法律?

file - 根据名称在终端中移动内容

linux - 如何在 Linux 上查找包含特定文本(字符串)的所有文件?

java - 如何将 JOption 弹出窗口置于最前面?

security - 允许以#(哈希)开头的链接安全吗?

mysql - Symfony 3 中带有 Guard 身份验证系统的 LDAP

Oracle RAC——创建目录

java - cucumber 中的可选参数抛出错误