Please help frustration is getting a but much with the useless feedback of my mentor ;-).
package com.codegym.task.task18.task1819;
/*
Combining files
TODO: Write the contents of the second file to the beginning of the first file
so that the files are combined.
*/
import java.io.*;
public class Solution {
public static void main(String[] args) throws IOException {
//TODO: read 2 files from the console
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String file1 = reader.readLine();
String file2 = reader.readLine();
reader.close();
//TODO: Create an input stream for the first file and read its contents.
FileInputStream inputStreamFile1 = new FileInputStream(file1);
FileOutputStream outputStreamFile2 = new FileOutputStream(file2, true);
while (inputStreamFile1.available() > 0) {
int a = inputStreamFile1.read();
outputStreamFile2.write(a);//write the contents of file1 naar file2 append (at the end)
}
inputStreamFile1.close();
outputStreamFile2.close();
//TODO: Then create an output stream for the first file.
// And an input stream for the second file.
FileOutputStream outputStreamFile1 = new FileOutputStream(file1);
FileInputStream inputStreamFile2 = new FileInputStream(file2);
//TODO: read file 2 (all of its contents of file1 and file2 and copy it to file 1 overwriting the existing text
while (inputStreamFile2.available() > 0) {
int b = inputStreamFile2.read();
outputStreamFile1.write(b);//overwriting the existing text
}
outputStreamFile1.close();
inputStreamFile2.close();
}
}