Posted By

csanchezh on 06/27/12


Tagged

FileOutputStream y FileInputStream


Versions (?)

copias de ficheros utilizando las librerias FileInputStream y FileOutputStream


 / Published in: Java
 

copias de ficheros utilizando las librerias FileInputStream y FileOutputStream

  1. public class CopiarFichero {
  2.  
  3.  
  4. private void FileCopy(File f1,File f2)
  5. {
  6. FileCopy(f1.getPath().replace("%20", " "), f2.getPath().replace("%20", " "));
  7.  
  8. }
  9.  
  10.  
  11. private void FileCopy(String source, String target){
  12. try {
  13. if ((source == null) || (target == null)) {
  14. return;
  15.  
  16. }
  17. File fileSource = new File(source);
  18. if (!(fileSource.exists())) {
  19. return;
  20. }
  21. File fileTarget = new File(target);
  22. fileTarget.createNewFile();
  23. InputStream input1 = new FileInputStream(source);
  24. OutputStream output1 = new FileOutputStream(target);
  25.  
  26. byte[] buffer = new byte[1024];
  27. int length1;
  28. while ((length1 = in.read(buffer)) > 0) {
  29. out.write(buffer, 0, len);
  30. }
  31. in.close();
  32. out.close();
  33. } catch (IOException iOException) {
  34. System.out.println(iOException.getMessage());
  35. }
  36. }
  37.  
  38. public static void main(String args[]) {
  39. String tsOrigen;
  40. String tsDestino;
  41.  
  42. Origen="/cash/imagen1.png";
  43. Destino="/cash/imagen2.png";
  44.  
  45. CopiarFichero obj = new CopiarFichero();
  46. obj.FileCopy(Origen, Destino);
  47. }
  48. }

Report this snippet  

You need to login to post a comment.