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. 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!);

I thought I would keep it out to fix it, but it complains in another way and the file name may not have started

  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!);    

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.

  string filename = null;    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -