java - 使用Java代码在Unix服务器上创建一个具有读写可执行权限的文件夹?

标签 java unix

是否可以使用 Java 代码在 Unix 服务器上创建一个具有读写可执行权限的文件夹?

我发现 Java 示例代码仅授予文件权限,而不授予文件夹权限。

最佳答案

https://docs.oracle.com/javase/tutorial/essential/io/dirs.html#create

You can create a new directory by using the createDirectory(Path, FileAttribute) method. If you don't specify any FileAttributes, the new directory will have default attributes. For example:

Path dir = ...; Files.createDirectory(path); 

The following code snippet creates a new directory on a POSIX file system that has specific permissions:

Set<PosixFilePermission> perms =
PosixFilePermissions.fromString("rwxr-x---"); 
FileAttribute<Set<PosixFilePermission>> attr =
PosixFilePermissions.asFileAttribute(perms); Files.createDirectory(file, attr); 

To create a directory several levels deep when one or more of the parent directories might not yet exist, you can use the convenience method, createDirectories(Path, FileAttribute). As with the createDirectory(Path, FileAttribute) method, you can specify an optional set of initial file attributes. The following code snippet uses default attributes:

关于java - 使用Java代码在Unix服务器上创建一个具有读写可执行权限的文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50329684/

相关文章:

java - 将 Jackson2 与 Spring 4.0 (MVC + REST+ Hibernate) 结合使用

linux - 如何在 Bash 中识别多行字符串中的目录路径,替换为对自己文件内容的引用?

unix - 文件创建/打开对 st_mtime 和 st_atime 的影响

javascript - 使用 I/O 从 webpge 运行 UNIX 可执行文件

bash - 在 mac bash 终端中使用 shell 命令时出现 "Illegal Byte sequence"错误

Java-检查数据库中是否已存在id

java - 类数组覆盖

java - 为什么Map记录output = 0,即使我在mapper中给出输出

unix - 一次中断所有 lerna --parallel 任务

java - weka java加载模型并使用测试数据集