I'm doing a program in java where I want to have an order of the images that I'm working with and I want to have a copy of it, change the name and have it in a specific folder. I have the following code.
JFileChooser fc = new JFileChooser();
int seleccion = fc.showOpenDialog(this);
//Si el usuario, pincha en aceptar
if (seleccion == JFileChooser.APPROVE_OPTION) {
try {
//Seleccionamos el fichero
File fichero = fc.getSelectedFile();
if (fichero.exists()) {
File fdest = new File(Paths.get(".").toAbsolutePath().normalize().toString() + "/" + conductor.getDni(), jTextField1.getText() + "." + FilenameUtils.getExtension(fichero.getAbsolutePath()));
Files.move(fichero.toPath(), fdest.toPath()); //esta parte del codigo no funciona
// FileUtils.copyFileToDirectory(fichero, fdest); --> esta parte si me mueve el archivo pero no como necesito exactamente
if (fdest.exists()) {
Documentacion d = new Documentacion();
d.setConductor(conductor);
d.setDescripcion(jTextField1.getText());
d.setRuta(fdest.getAbsolutePath());
DocumentacionJpaController controller = new DocumentacionJpaController(emf);
controller.create(d);
cargarTabla(conductor);
} else {
System.out.println("error no se pudo mover");
}
}
} catch (Exception ex) {
Logger.getLogger(AddDocumentos.class.getName()).log(Level.SEVERE, null, ex);
}
}
FileUtils.copyFileToDirectory works but for example if I have C: / a.jpg and I want to move it to C: /micarpeta/cedula.jpg when executing that instruction the following is created C: /micarpeta/cedula.jpg/a.jpg