CMPSC 56 Study Guide - Midterm Guide: Instance Variable, Call Stack, Observer Pattern

59 views7 pages
17 Nov 2017
School
Course
Professor

Document Summary

Objectinputstream(filestream); fileinputstream(cid:383)(cid:361)myfile. ser(cid:362)(cid:384); an objectinputstream (3) read the objects (4) cast the objects (5) Filewriter w = new filewriter(cid:383)(cid:361)file. txt(cid:362)(cid:384); w. write(cid:383)(cid:361)some string(cid:362)(cid:384); w. close(); try { All the i/o stuff (cid:373)ust (cid:271)e i(cid:374) a t(cid:396)(cid:455)/(cid:272)at(cid:272)h, a(cid:374)d if file. t(cid:454)t does(cid:374)(cid:859)t e(cid:454)ist, Filewritier will create it: the java. io. file class represents a file on disk, but not the actual contents of the file, to make a file object representing an existing file: File f = new file(cid:383)(cid:361)myfile. txt(cid:362)(cid:384): to make a new directory: File dir = new file(cid:383)(cid:361)mydir(cid:362)(cid:384); dir. mkdir(): to list the contents of a directory: if (dir. isdirectory()) { String[] dircontents = dir. list(); for (string s : dircontents) System. out. println(s): to get the absolute path of a file/directory: System. out. println(dir. getabsolutepath()): to delete a file/directory (returns true if successful): Boolean isdeleted = f. delete(): buffers give you a temporary holding place to group things until the holder is full; to chain a bufferedwriter onto a filewriter:

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers

Related Documents

Related Questions