It seems I'm not alone in my struggle with this one...
Can anybody provide some insight please.
Many thanks in advance
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 = null;
OutputStream fileOutputStream = null;
String sourceFileName = reader.readLine();
String destinationFileName = reader.readLine();
try {
fileInputStream = getInputStream(sourceFileName);
}
catch (Exception e1){
System.out.println("File does not exist");
sourceFileName = reader.readLine();
try {
fileInputStream = getInputStream(sourceFileName);
}
catch (Exception e2){
System.out.println("File still does not exist");
fileInputStream=null;
}
}
finally {
try {
fileOutputStream = getOutputStream(destinationFileName);
while (fileInputStream.available() > 0) {
int data = fileInputStream.read();
fileOutputStream.write(data);
}
}
catch (Exception e3) {
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);
}
}