COMP SCI 300 Lecture 8: LECTURE 8

53 views2 pages

Document Summary

What can go wrong: to read the contents of a file , create a file object from the file name. Permissions: create a scanner object from the file object. Might overwrite an existing or try to read a file that doesn"t exist. Non-text files which might interact weirdly with the scanner: use scanner methods to read the contents of the file. Different data types next() when the file (scanner) is empty. The throws statement: we use this statement to , alert java, also other users of our code, that a piece of code is unsafe it may cause an exception, it goes , always at the end of the method header. Avoiding exception: we can avoid some exceptions with careful coding, if(f. exists()){ Scanner s = new scanner(f);//dangerous step //because f might not be a real file: //still new the throws , exception.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents

Related Questions