13.07.2015 Views

I/O Fundamentals

I/O Fundamentals

I/O Fundamentals

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Java Input and Outputvoid write(type[], intoffset, int length)void write(int)void write(String)(Writer only!)void write(String, intoffset, int length)(Writer only!)Similar to write(type[]), but only length units of data will bewritten from type[], starting at the offset.Writes a single item (char for Writer, byte forOutputStream) to the file.Writes the contents of a java.lang.String to the file.Writes the substring starting at offset and length characters longto the file.Reading and Writing FilesTo read and write from files on a disk, use the following classes:• FileInputStream• FileOutputStream• FileReader• FileWriterThey provide concrete implementations of the abstract input and output andoutput classes above.Each of these has a few constructors, where class is the name of one of the aboveclasses:• class(File) - create an input or output file based on the abstract path namepassed in• class(String)- create an input or output file based on the String path name• class(FileDescriptor)- create an input or output file based on aFileDescriptor (you generally won't use this and this class will not discussit)• class(String, boolean)- [for output classes only] create an input oroutput file based on the path name passed in, and if the boolean parameter istrue, append to the file rather than overwrite itFor example, we could copy one file to another by using:Java Input and Output -10© 1996-2003 jGuru.com. All Rights Reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!