【发布时间】:2012-07-29 01:41:42
【问题描述】:
我需要创建一些目录和文件,它们都应该具有 0600 权限。
当我从 NetBeans Debug 运行时:
创建目录后,当我尝试在那里存储一些文件时,我收到IOException 并显示“Permission Denied”消息,而目录和文件是使用相同的应用程序同时使用相同的用户创建的,所以我认为 0600(所有者读/写)应该工作。
并且在运行 Jar 文件时,chmod 根本不起作用!
我的代码是:
if(!Dest.exists()){
boolean res=dirs.mkdirs();
if(res){
Runtime.getRuntime().exec("chmod -R 600 '"+dirs.getAbsolutePath()+"'");
}
}
File Destination=new File(Dest, source.getName());
documentManager.copyFile(source, Destination);
而copyFile是:
public static void copyFile(File sourceFile, File destFile) throws FileNotFoundException,IOException {
if(!destFile.exists()) {
destFile.createNewFile();
}
FileChannel source = null;
FileChannel destination = null;
try {
source = new FileInputStream(sourceFile).getChannel();
destination = new FileOutputStream(destFile).getChannel();
destination.transferFrom(source, 0, source.size());
}
finally {
if(source != null) {
source.close();
}
if(destination != null) {
Runtime.getRuntime().exec("chmod 600 '"+destFile.getAbsolutePath()+"'");
destination.close();
}
}
}
有什么问题?
谢谢
【问题讨论】:
-
请发布您的堆栈跟踪。大概自己分析吧。异常是从哪里抛出的?
标签: java linux io file-permissions chmod