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 ); } } }
new file()
constructor offile
class. new instance offile
created.scores.dat
must file exists in same directory of code.- yes
finally
optional
check java doc more information file
class.
Comments
Post a Comment