I tried copying code from others but it is clearly that I have no clue how it works. Can someone please enlighten me?
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));
//String sourceFileName = reader.readLine();// reads data from keyboard
String destinationFileName = reader.readLine();// reads data from keyboard
InputStream fileInputStream = null;
try {
String sourceFileName = reader.readLine();
fileInputStream = getInputStream(sourceFileName);
} catch (FileNotFoundException e){
System.out.println("File does not exist");//The main method must handle exceptions thrown by the getInputStream method. If an exception occurs, you should display "File does not exist.".
String sourceFileName = reader.readLine();
fileInputStream = getInputStream(sourceFileName);
}
String sourceFileName = reader.readLine();
fileInputStream = getInputStream(sourceFileName);
OutputStream fileOutputStream = getOutputStream(destinationFileName);
while (fileInputStream.available() > 0) {//The program must copy the contents of the first file to the second one.
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);
}
}