/**
* 增加权限,使路径可上传文件
*/
public static void addChmod777(String filePath) throws IOException {
if (!System.getProperty("os.name").startsWith("Win")) {
String cmdGrant = "chmod 777 " + filePath;
BaseLogMethod.logInfo(TAG, "File Augmentation after Moving:" + cmdGrant);
Runtime.getRuntime().exec(cmdGrant);
}
}
/**
* 增加权限,使路径及子路径都有权限
*/
public static void addRChmod777(String filePath) throws IOException {
if (!System.getProperty("os.name").startsWith("Win")) {
String cmdGrant = "chmod -R 777 " + filePath;
BaseLogMethod.logInfo(TAG, ".addRChmod777: File Augmentation after Moving:" + cmdGrant);
Runtime.getRuntime().exec(cmdGrant);
}
}
java 为文件及文件夹添加权限
最新推荐文章于 2023-09-05 05:41:53 发布
该博客主要介绍了如何在非Windows环境下通过Java代码使用chmod命令为文件和目录添加上传权限。提供了两个静态方法,`addChmod777`用于单一文件的权限设置,`addRChmod777`则用于递归赋予路径及其子目录权限。这些方法对于确保文件系统的可写性至关重要。
摘要由CSDN通过智能技术生成