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

c# - passing input text from view to contoller with FacebookContext using Facebook app -

ios - Does Core Data autoupdate a many to many relationship on saving -

Calling a C++ function from C# by passing a string with variable size to it -