Advertisement
jaVer404

level18.lesson05.task04

Nov 3rd, 2015
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.24 KB | None | 0 0
  1. package com.javarush.test.level18.lesson05.task04;
  2.  
  3. /* Реверс файла
  4. Считать с консоли 2 имени файла: файл1, файл2.
  5. Записать в файл2 все байты из файл1, но в обратном порядке
  6. Закрыть потоки. Не использовать try-with-resources
  7. */
  8.  
  9. import java.io.*;
  10.  
  11. public class Solution
  12. {
  13.     public static void main(String[] args) throws IOException
  14.     {
  15.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  16.         String fileName1 = reader.readLine();
  17.         String fileName2 = reader.readLine();
  18.         FileInputStream fileInputStream = new FileInputStream(fileName1);
  19.         FileOutputStream fileOutputStream = new FileOutputStream(fileName2);
  20.         int fileSize = (int) new File(fileName1).length();
  21.         byte[] myBytes = new byte[fileSize];
  22.         while (fileInputStream.available() > 0)
  23.         {
  24.             int count = fileInputStream.read(myBytes);
  25.         }
  26.         for (int i = myBytes.length - 1; i >= 0; i--)
  27.         {
  28.             fileOutputStream.write(myBytes[i]);
  29.         }
  30.         reader.close();
  31.         fileInputStream.close();
  32.         fileOutputStream.close();
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement