Advertisement
joseleonweb

Untitled

Feb 26th, 2021
717
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.06 KB | None | 0 0
  1. package m3uf3path.backup;
  2.  
  3. import java.io.File;
  4. import java.io.FileInputStream;
  5. import java.io.FileOutputStream;
  6. import java.io.IOException;
  7. import java.io.InputStream;
  8. import java.io.OutputStream;
  9.  
  10.  
  11. public class CopyFile {
  12.     public static void main(String[] args) {
  13.         InputStream inputStream = null;
  14.         OutputStream outputStream = null;
  15.         try {
  16.             File archivoOriginal = new File("D:\\code\\source\\original.txt");
  17.             File archivoCopia = new File("D:\\code\\destination\\copia.txt");
  18.             inputStream = new FileInputStream(archivoOriginal);
  19.             outputStream = new FileOutputStream(archivoCopia);
  20.             byte[] buffer = new byte[1024];
  21.             int length;
  22.             while ((length = inputStream.read(buffer)) > 0) {
  23.                 outputStream.write(buffer, 0, length);
  24.             }
  25.             inputStream.close();
  26.             outputStream.close();
  27.             System.out.println("Archivo copiado.");
  28.         } catch (IOException e) {
  29.             e.printStackTrace();
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement