Can someone more experienced than me help me with this? I am just curious if this is possible to resolve this task conditions with my way of thinking.
I know all the conditions are false but in my opinion this way of thinking is logic and correct.
package com.codegym.task.task18.task1819;
/*
Combining files
*/
import java.io.*;
import java.util.ArrayList;
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String file1 = reader.readLine();
String file2 = reader.readLine();
reader.close();
FileInputStream file1InputStream = new FileInputStream(file1);
FileOutputStream file1OutputStream = new FileOutputStream(file1);
FileInputStream file2InputStream = new FileInputStream(file2);
FileOutputStream file2OutputStream = new FileOutputStream(file2);
// Making arrayList
ArrayList<Integer> fileList = new ArrayList<>();
//Adding all the elements from second file to the arrayList so they are
//on the beggining on the list
while(file2InputStream.available() > 0){
int read = file2InputStream.read();
fileList.add(read);
}
//then adding elements to the arrayList before the elements from file2
while(file1InputStream.available() > 0){
int read = file1InputStream.read();
fileList.add(read);
}
//Deleting files from file1
file1InputStream.reset();
//Adding list to the file1 so elements from the file2 are first and then file1
for(int i = 0; i < fileList.size(); i++){
file1OutputStream.write(i);
}
file1InputStream.close();
file2InputStream.close();
}
}