Guest User

Untitled

a guest
Feb 15th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. import java.io.FileNotFoundException;
  2. import java.io.IOException;
  3. import java.nio.file.Files;
  4. import java.nio.file.Path;
  5. import java.nio.file.Paths;
  6. import java.nio.file.StandardCopyOption;
  7. import java.util.logging.Level;
  8. import java.util.logging.Logger;
  9.  
  10. /*
  11. * Creado por: David Pérez Sánchez
  12. * Universidad Politécnica de Chiapas.
  13. * Fecha de Creación: 14/02/2019
  14. */
  15.  
  16. /**
  17. * @author David Pérez S.
  18. */
  19. public class CopiadorArchivos {
  20.  
  21. static final Logger LOGGER = Logger.getAnonymousLogger();
  22.  
  23. // Requiere de la ruta (path) completa o absoluta, tanto de origen como de destino.
  24. public void copiarArchivo(String origenArchivo, String destinoArchivo) {
  25. try {
  26. Path origenPath = Paths.get(origenArchivo);
  27. Path destinoPath = Paths.get(destinoArchivo);
  28. // Sobreescribe el fichero de destino si existe uno igual, el tercer parámetro es configurable.
  29. Files.copy(origenPath, destinoPath, StandardCopyOption.REPLACE_EXISTING);
  30. System.out.println("\t[ Copiado exitoso ]");
  31. } catch (FileNotFoundException ex) {
  32. // Archivo no encontrado
  33. LOGGER.log(Level.SEVERE, ex.getMessage());
  34. System.out.println("\t[ No se pudo copiar el archivo ]");
  35. } catch (IOException ex) {
  36. // Algún error de escritura u otro.
  37. LOGGER.log(Level.SEVERE, ex.getMessage());
  38. System.out.println("\t[ No se pudo copiar el archivo ]");
  39. }
  40. }
  41. }
Add Comment
Please, Sign In to add comment