java - What is the correct way to do this? Initialization/Symbol not found errors -
I am practicing with scanners and exceptions and they are quite new so maybe I am missing something here: / P>
This is the first method that the compiler says that it can not get a file name or name. I thought I would keep it out to fix it, but it complains in another way and the file name may not have started Start to empty the value of the filename. In this way, if the catch block is entered, then there will be a value to use when you print the error message. Do {try {System.out.print ("Enter File Name:"); String filename = KNXTine (); Scanner F = New Scanner (new file (filename)); Did = true; } Hold (FileNotFoundException ex1) {System.out.println ("file" + filename + "does not exist."); } Hold (exception e) {System.out.println ("unexpected exception"); }} While (done!);
scanner k = new scanner (System.in), f; String filename; Boolean did = wrong; // user request file {try {System.out.print ("Enter file name:"); File name = k.nextLine (); F = new scanner (new file (filename)); Did = true; } Hold (FileNotFoundException ex1) {System.out.println ("file" + filename + "does not exist."); } Hold (exception e) {System.out.println ("unexpected exception"); }} While (done!);
string filename = null;
Comments
Post a Comment