COMP 249 Lecture 15: FileIO9

52 views4 pages

Document Summary

This program illustrates how files can be read through. // when using bufferedreader class, two types of exceptions can be thrown, // this class must either catch or declare that exception. import java. util. scanner; import java. io. printwriter; import java. io. fileoutputstream; import java. io. filenotfoundexception; import java. io. fileinputstream; import java. io. bufferedreader; import java. io. filereader; import java. io. ioexception; // a method that the names of an input and output files (as streams) // then copies the input file to the output file public class fileio9{ public static void filecopy(bufferedreader infilestreamname, printwriter outfilestreamname) // read line by line from input file and copy it to output file. String s; s = infilestreamname. readline(); while(s != null) // the readline() method returns null when it is eof. // must close the files to flush the buffers infilestreamname. close(); outfilestreamname. close(); outfilestreamname. println(s); s = infilestreamname. readline(); throws ioexception. // a method that takes a stream file name and display the contents of this file public static void displayfilecontents(bufferedreader infilestreamname) throws ioexception.

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