Advertisement
Jakzon123

java copy binary between files

Nov 13th, 2022
842
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 KB | None | 0 0
  1. import java.io.*;
  2.  
  3. public class Test {
  4.     public static void main(String[] args) throws Exception {
  5.         BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream("file.txt"));
  6.         BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream("out.txt"));
  7.  
  8.         try {
  9.             int ch;
  10.             while ((ch = inputStream.read()) != -1) {
  11.                 outputStream.write(ch);
  12.             }
  13.             inputStream.close();
  14.             outputStream.close();
  15.         }
  16.         catch (Exception e) {
  17.             System.exit(1);
  18.         }
  19.  
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement