В IDE все компилирует, считывание файла если он не верен проходит 2 раза, если верен то 1, считывание второго файла всегда 1 раз, но валидатор не пускает, помогите разобраться.
package com.javarush.task.task09.task0929;
import java.io.*;
/*
Обогатим код функциональностью!
*/
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();
for(int i = 0; i < 2; i++) {
try {
InputStream fileInputStream = getInputStream(sourceFileName);
OutputStream fileOutputStream = getOutputStream(destinationFileName);
while (fileInputStream.available() > 0) {
int data = fileInputStream.read();
fileOutputStream.write(data);
}
fileInputStream.close();
fileOutputStream.close();
break;
}
catch (FileNotFoundException e){
System.out.println("Файл не существует.");
sourceFileName = reader.readLine();
}
}
}
public static InputStream getInputStream(String fileName) throws IOException {
return new FileInputStream(fileName);
}
public static OutputStream getOutputStream(String fileName) throws IOException {
return new FileOutputStream(fileName);
}
}
package com.javarush.task.task09.task0929;
import java.io.*;
/*
Обогатим код функциональностью!
*/
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();
for(int i = 0; i < 2; i++) {
try {
InputStream fileInputStream = getInputStream(sourceFileName);
OutputStream fileOutputStream = getOutputStream(destinationFileName);
while (fileInputStream.available() > 0) {
int data = fileInputStream.read();
fileOutputStream.write(data);
}
fileInputStream.close();
fileOutputStream.close();
break;
}
catch (FileNotFoundException e){
System.out.println("Файл не существует.");
sourceFileName = reader.readLine();
}
}
}
public static InputStream getInputStream(String fileName) throws IOException {
return new FileInputStream(fileName);
}
public static OutputStream getOutputStream(String fileName) throws IOException {
return new FileOutputStream(fileName);
}
}