Code works perfectly fine!
public class Solution {
public static void main(String[] args) throws IOException {
// write your code here
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String st = br.readLine();
File file = new File(st);
if(!file.exists()) {
file.createNewFile();
}
FileWriter fw = new FileWriter(file);
BufferedWriter bw = new BufferedWriter(fw);
while (true){
String s = br.readLine();
if(s.equals("exit"))
{
bw.write(s,0,s.length());
bw.flush();
bw.close();
break;
}
else {
bw.write(s,0,s.length());
bw.newLine();
}
}
}
}
Anatoly
Level 17
Validator is wrong with that
Resolved
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Guadalupe Gagnon
22 February 2021, 15:19solution
#1 Checking if the file exists, unless the task specifically says to do so, is an automatic fail on codegym. This is because the validator does not have a harddrive. All it does is test input and output. If us students had access to codegym's hard drives we could inadvertently (or not) really mess their system up. Get rid of:
and pass the input string for the file name directly to the FileWriter. +2
Anatoly
22 February 2021, 19:44
Thank you Very much! Now i got why validator do not like my decision much!
+1