Advertisement
Didart

Copy Bytes

Jan 25th, 2023 (edited)
743
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1. package StreamsFilesAndDirectories4;
  2.  
  3. import java.io.*;
  4.  
  5. public class CopyBytes {
  6.     public static void main(String[] args) throws IOException {
  7.  
  8.         String pathIn = "input.txt";
  9.         String pathOut = "output.txt";
  10.  
  11.         FileInputStream in = new FileInputStream(pathIn);
  12.         FileOutputStream out = new FileOutputStream(pathOut);
  13.  
  14.         int oneByte = in.read();
  15.         while (oneByte >= 0) {
  16.  
  17.             if (oneByte == 32 || oneByte == 10) {
  18.                 out.write((char) oneByte);
  19.             } else {
  20.                 String digits = String.valueOf(oneByte);
  21.                 for (int index = 0; index < digits.length(); index++) {
  22.                     out.write(digits.charAt(index));
  23.                 }
  24.             }
  25.             oneByte = in.read();
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement