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