COSC 236 Lecture Notes - Lecture 4: Rieti, Exception Handling, Ath

45 views2 pages

Document Summary

The file class in the java. io package represents files. Import java. io,*: create a file object to get information about a file on the disk ( to read file). (cid:894)(cid:272)reati(cid:374)g a file o(cid:271)je(cid:272)t does(cid:374)"t (cid:272)reate a (cid:374)e(cid:449) file o(cid:374) (cid:455)our disk. (cid:895) If (f. exists() && f. length() > 1000) { f. delete(); *you have a file object that represents the file. Returns whether file is able to be read. To read a file, create a file object and pass it as a parameter when constructing a. Creating a scanner for a file, general syntax: Scanner input = new scanner(f); // f is the file object. Relative path: does not specify any top-level folder: (cid:862)(cid:374)a(cid:373)es. dat(cid:863, (cid:862)i(cid:374)put/ki(cid:374)glear. t(cid:454)t(cid:863) Absolute path: spe(cid:272)ifies dri(cid:448)e letter or top (cid:862)/(cid:863) folder. *java assumes that your file is in the same folder as the . java file: (cid:862)c:/do(cid:272)u(cid:373)e(cid:374)ts/s(cid:373)ith/h(cid:449)6/i(cid:374)put/data. (cid:272)s(cid:448)(cid:863, windows systems also use backslashes to separate folders.

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