package com.codegym.task.task09.task0929;
import java.io.*;
/*
Let's make the code do something useful!
*/
class Counter {
static int i = 0;
}
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String sourceFileName = reader.readLine();
String destinationFileName = reader.readLine();
tryThis(sourceFileName, destinationFileName);
}
static void tryThis(String iS, String oS) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
if(Counter.i == 0) {
try {
copyFile(getInputStream(iS), getOutputStream(oS));
} catch (Exception e) {
Counter.i++;
System.out.println("File does not exist.");
String iS2 = reader.readLine();
//String oS2 = reader.readLine();
tryThis(iS2, oS);
}
}
}
static void copyFile(InputStream iSt, OutputStream oSt) throws IOException {
while (iSt.available() > 0) {
int data = iSt.read();
oSt.write(data);
}
iSt.close();
oSt.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);
}
}
Let's add my solution to the list of solutions that don't meet the third requirement
Under discussion
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Guadalupe Gagnon
17 December 2018, 00:34
Try this:
0
Guadalupe Gagnon
17 December 2018, 00:38
I just moved all your code from the methods that you made to the main method as that is what the requirements called for. Also, I got rid of the counter class and put the code for that in a for loop as this is a structure that already is convenient for a counter. The requirements also specify that you need to read the source file, and if it doesn't read the source file one more time, then only after this read the destination file. Your code reads the source then the destination immediately following, which is probably the only thing failing your code. Hopefully this works, I'm not sure because it wont verify my code as the problem is already closed.
0