0
我正在使用以下方法将文件从一个文件夹(源)移动到另一个(目标)。我添加了一个检查来查看文件是否存在,该文件返回true,但文件仍然没有移动到目的地。文件移动不起作用
在这里,源路径是:
C:\ App_v10.4 \ RAP009.jrxml和C:\ App_v10.4 \ RAP009.jasper
目的地:
C:\用户\ Avijit \桌面\ RAP009.jrxml和C:\用户\ Avijit \桌面\ RAP009.jasper
private void moveFile(List<String> source, String destination)
throws IOException {
if (null != source && !source.isEmpty()) {
for (String path : source) {
try {
File file = new File(path);
System.out.println(path);
System.out.println("File :" + file.exists());
System.out.println(new File(destination + file.getName()));
System.out.println(file.getCanonicalPath());
System.out.println(file.getAbsolutePath());
System.out.println(file.getPath());
if (file.renameTo(new File(destination + file.getName()))) {
System.out.println("File is moved successful!");
} else {
System.out.println("File has failed to move!");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
控制台O/P:
C:\App_v10.4\RAP009.jrxml
File :true
C:\Users\Avijit\Desktop\RAP009.jrxml
C:\App_v10.4\RAP009.jrxml
C:\App_v10.4\RAP009.jrxml
C:\App_v10.4\RAP009.jrxml
File has failed to move!
C:\App_v10.4\RAP009.jasper
File :true
C:\Users\Avijit\Desktop\RAP009.jasper
C:\App_v10.4\RAP009.jasper
C:\App_v10.4\RAP009.jasper
C:\App_v10.4\RAP009.jasper
File has failed to move!
你对目标目录有写访问权限? – EJP 2013-04-12 23:07:16
感谢您看一看, 是的,我对目标目录有写访问权限ectory ... – Avijit 2013-04-13 15:29:21