I implemented infinite loop to ask a correct file name... but if I uncomment the grader take "too long"
Locally it works ??
package fr.codegym.task.task09.task0929;
import java.io.*;
/*
Modifions le code pour qu'il fasse quelque chose d'utile !
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader lecteur = new BufferedReader(new InputStreamReader(System.in));
String nomFichierSource = lecteur.readLine();
String nomFichierDestination = lecteur.readLine();
/*** load the source file ***/
InputStream fileInputStream = null;
//while (fileInputStream == null) { //hide the while, it cause grader run for too long
try {
fileInputStream = obtenirInputStream(nomFichierSource);
} catch (IOException e) {
System.out.println("Le fichier n'existe pas.");
nomFichierSource = lecteur.readLine();
fileInputStream = obtenirInputStream(nomFichierSource);
}
//}
/*** load the destination file to prove its existence ***/
InputStream inputStreamCheckDestinationExistence = null;
//while (inputStreamCheckDestinationExistence == null) { //hide the while, it cause the grader run for too long
try {
inputStreamCheckDestinationExistence = obtenirInputStream(nomFichierDestination);
} catch (IOException e) {
System.out.println("Le fichier n'existe pas.");
nomFichierDestination = lecteur.readLine();
inputStreamCheckDestinationExistence = obtenirInputStream(nomFichierDestination);
}
//}
inputStreamCheckDestinationExistence.close();//so the destination file should really exist
//write data to destination as everything should be available
OutputStream fileOutputStream = null;
fileOutputStream = obtenirOutputStream(nomFichierDestination);
while (fileInputStream.available() > 0) {
int donnees = fileInputStream.read();
fileOutputStream.write(donnees);
}
fileInputStream.close();
fileOutputStream.close();
}
public static InputStream obtenirInputStream(String nomFichier) throws IOException {
return new FileInputStream(nomFichier);
}
public static OutputStream obtenirOutputStream(String nomFichier) throws IOException {
return new FileOutputStream(nomFichier);
}
}