Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.javarush.test.level18.lesson05.task04;
- /* Реверс файла
- Считать с консоли 2 имени файла: файл1, файл2.
- Записать в файл2 все байты из файл1, но в обратном порядке
- Закрыть потоки. Не использовать try-with-resources
- */
- import java.io.*;
- public class Solution
- {
- public static void main(String[] args) throws IOException
- {
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- String fileName1 = reader.readLine();
- String fileName2 = reader.readLine();
- FileInputStream fileInputStream = new FileInputStream(fileName1);
- FileOutputStream fileOutputStream = new FileOutputStream(fileName2);
- int fileSize = (int) new File(fileName1).length();
- byte[] myBytes = new byte[fileSize];
- while (fileInputStream.available() > 0)
- {
- int count = fileInputStream.read(myBytes);
- }
- for (int i = myBytes.length - 1; i >= 0; i--)
- {
- fileOutputStream.write(myBytes[i]);
- }
- reader.close();
- fileInputStream.close();
- fileOutputStream.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement