+ 1

My code exit with code 1? why?

hi guys I have following code in Main class and 1 file called 1.txt why does'n work correctly? in console : Process finished with exit code 1 import java.io.FileNotFoundException; import java.io.FileReader; public class Main { public static void main(String[] args) throws FileNotFoundException { FileReader reader=new FileReader("1.txt"); } }

24th Nov 2020, 4:03 PM
saeedeh
3 odpowiedzi
+ 2
//try this import java.io.*; public class Main { public static void main(String[] args) throws FileNotFoundException { try { new File("1.txt").createNewFile(); } catch (IOException e) { System.out.println(e); } FileReader reader=new FileReader("1.txt"); } }
24th Nov 2020, 8:13 PM
zemiak
+ 2
zemiak Martin Taylor thank you guys😊
24th Nov 2020, 8:15 PM
saeedeh
+ 1
Martin Taylor I don't know what problem is both text file and class file are in the same folder when I put the following code in the try block it solve. FileReader reader= new File Reader("1.txt")
24th Nov 2020, 4:42 PM
saeedeh