With a little hepl from comment section i manage to write the code :), this code do the job, but nevertheless i can t pass the task: "Be sure that the program copies the contents successfully." I don t understand, i manage to coppy everything from file1 to file 2. Any hint? Tk you!
package com.codegym.task.task09.task0929;
import java.io.*;
/*
Let's make the code do something useful!
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
InputStream fileInputStream;
try {
String sourceFileName = reader.readLine();
fileInputStream = getInputStream(sourceFileName);
} catch (FileNotFoundException e){
System.out.println("File does not exist.");
}
String sourceFileName2 = reader.readLine();
fileInputStream = getInputStream(sourceFileName2);
String destinationFileName = reader.readLine();
OutputStream fileOutputStream = getOutputStream(destinationFileName);
while (fileInputStream.available() > 0) {
int data = fileInputStream.read();
fileOutputStream.write(data);
}
fileInputStream.close();
fileOutputStream.close();
}
public static InputStream getInputStream(String fileName) throws IOException {
return new FileInputStream(fileName);
}
public static OutputStream getOutputStream(String fileName) throws IOException {
return new FileOutputStream(fileName);
}
}