Для чтения из файла используй поток FileInputStream, для записи в файл - FileOutputStream
а я что использую???
Во второй файл нужно записать все байты из первого в обратном порядке.
именно это и просходит в моих файлах!!
Потоки FileInputStream и FileOutputStream должны быть закрыты.
все клозе
package com.javarush.task.task18.task1809;
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/*
Реверс файла
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader= new BufferedReader(new InputStreamReader(System.in));
String firstFileName = reader.readLine();
String secondFileName = reader.readLine();
reader.close();
FileInputStream firstInput = new FileInputStream(firstFileName);
FileInputStream secondInput = new FileInputStream(secondFileName);
FileOutputStream firstOutput = new FileOutputStream(firstFileName);
FileOutputStream secondOutput = new FileOutputStream(secondFileName);
byte [] firstBuffer = new byte[firstInput.available()];
byte [] secondBuffer = new byte[secondInput.available()];
int firstReal =0;
int secondReal= 0;
while (firstInput.available()>0){
firstReal = firstInput.read(firstBuffer);
}
while (secondInput.available()>0){
secondReal = secondInput.read(secondBuffer);
}
firstInput.close();
secondInput.close();
for (int i = 0; i < firstBuffer.length / 2; i++) {
byte tmp = firstBuffer[i];
firstBuffer[i] = firstBuffer[firstBuffer.length - i - 1];
firstBuffer[firstBuffer.length - i - 1] = tmp;
}
for (int i = 0; i < secondBuffer.length / 2; i++) {
byte tmp = secondBuffer[i];
secondBuffer[i] = secondBuffer[secondBuffer.length - i - 1];
secondBuffer[secondBuffer.length - i - 1] = tmp;
}
firstOutput.write(secondBuffer,0,secondReal);
secondOutput.write(firstBuffer,0,firstReal);
firstOutput.close();
secondOutput.close();
}
}