是否可以使用 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/