在java中,文件的权限对于不同的操作系统有不同的权限。 java 处理一些通用的权限。
检查文件是否允许:
file.canExecute(); – return true, file is executable; false is not.
file.canWrite(); – return true, file is writable; false is not.
file.canRead(); – return true, file is readable; false is not.
设置文件权限:
file.setExecutable(boolean); – true, allow execute operations; false to disallow it.
file.setReadable(boolean); – true, allow read operations; false to disallow it.
file.setWritable(boolean); – true, allow write operations; false to disallow it.
在*nix系统中,你可能需要配置更加明确的文件权限,如设置某个文件的权限为777.但是,java IO类没有相关方法。不过可以使用以下workaround:
Runtime.getRuntime()。exec("chmod 777 file");
在java中,文件的权限对于不同的操作系统有不同的权限。 java 处理一些通用的权限。
检查文件是否允许:
file.canExecute(); – return true, file is executable; false is not.
file.canWrite(); – return true, file is writable; false is not.
file.canRead(); – return true, file is readable; false is not.
设置文件权限:
file.setExecutable(boolean); – true, allow execute operations; false to disallow it.
file.setReadable(boolean); – true, allow read operations; false to disallow it.
file.setWritable(boolean); – true, allow write operations; false to disallow it.
在*nix系统中,你可能需要配置更加明确的文件权限,如设置某个文件的权限为777.但是,java IO类没有相关方法。不过可以使用以下workaround:
Runtime.getRuntime().exec("chmod 777 file");
?