Skip to content

Instantly share code, notes, and snippets.

@dmersiyanov
Last active June 13, 2017 15:00
Show Gist options
  • Save dmersiyanov/5fa0e09626a8b40aad4626d829a9a309 to your computer and use it in GitHub Desktop.
Save dmersiyanov/5fa0e09626a8b40aad4626d829a9a309 to your computer and use it in GitHub Desktop.
Решение задачи task1809 - Реверс файла. Считать с консоли 2 имени файла: файл1, файл2. Записать в файл2 все байты из файл1, но в обратном порядке. Закрыть потоки.
package com.javarush.task.task18.task1809;
/*
Реверс файла
*/
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String file1 = br.readLine();
String file2 = br.readLine();
FileInputStream fis = new FileInputStream(file1);
FileOutputStream fos = new FileOutputStream(file2);
ArrayList<Integer> list = new ArrayList<>();
while (fis.available() > 0) {
int temp = fis.read();
list.add(0,temp);
}
for(int i = 0; i < list.size(); i++) fos.write(list.get(i));
fis.close();
fos.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment