Advertisement
Tsuki11

Untitled

Jun 6th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. import java.io.*;
  2. import java.nio.file.Files;
  3.  
  4. public class L3_CopyBytes {
  5. public static void main(String[] args) throws IOException {
  6. // BufferedReader in = new BufferedReader(new FileReader("inputLab.txt"));
  7.  
  8. File file = new File("D:\\FilesStreams\\Lab\\04. Java-Advanced-Files-and-Streams-Lab-Resources\\input.txt");
  9.  
  10. byte[] bytes = Files.readAllBytes(file.toPath());
  11.  
  12. Writer writer = new FileWriter("outputBytes.txt");
  13.  
  14. OutputStream result = new FileOutputStream("outBytes1");
  15. for (byte b : bytes) {
  16. String outSymbol = String.valueOf(b);
  17.  
  18. if (b == 32) {
  19. outSymbol = " ";
  20. result.write(b);
  21.  
  22. } else if (b == 10) {
  23. outSymbol = System.lineSeparator();
  24. result.write(b);
  25. }else{
  26. for (int i = 0; i < outSymbol.length(); i++) {
  27. result.write(outSymbol.charAt(i));
  28. }
  29. }
  30.  
  31. writer.write(outSymbol);
  32.  
  33. }
  34.  
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement