exception - New "File" in java -


1. new file in new file("scores.dat") line mean? create new file?

2. when run piece of code, output: "java.io.filenotfoundexception: scores.dat (the system cannot find file specified)" know problem is?

3. there not "finally" section in code; putting "finally" optional in exceptions?

import java.util.scanner; import java.io.file; import java.io.ioexception;  public class readandprintscores {     public static void main(string[] args)     {            try         {             scanner s = new scanner( new file("scores.dat") );             while( s.hasnextint() )             {                 system.out.println( s.nextint() );             }         }         catch(ioexception e)         {              system.out.println( e );         }     } } 

  1. new file() constructor of file class. new instance of file created.
  2. scores.dat must file exists in same directory of code.
  3. yes finally optional

check java doc more information file class.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -