J'utilise la méthode suivante pour déplacer des fichiers d'un dossier (source) à un autre (destination). J'ai ajouté une vérification pour voir si le fichier existe qui renvoie vrai, mais toujours le fichier ne se déplace pas à la destination.Le déplacement du fichier ne fonctionne pas
Ici, les chemins source sont:
C: \ App_v10.4 \ RAP009.jrxml et C: \ App_v10.4 \ RAP009.jasper
Destination:
C: \ Users \ avijit \ Desktop \ RAP009.jrxml et C: \ Users \ avijit \ Desktop \ 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();
}
}
}
}
Console 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!
avoir un accès en écriture au répertoire cible? – EJP
Merci d'avoir jeté un œil, Oui j'ai un accès en écriture au répertoire cible ectory ... – Avijit