Reader The value is returned as a unicode Java. io. Reader +readO:int Reads the next character from the input stream. The value returned is an int in the range from 0 to 65535, which represents a Unicode character. Returns-1 at the end of the stream +read(cbuf: char[D): int Reads characters from the input stream into an array Returns the actual number of characters read Returns-I at the end of the stream +read(cbuyf: charlY, off: Reads characters from the input stream and stores into cbuf[off], cbuf[off+l] int, len: int): int cbufloff+len-1. The actual number of bytes read is returned. Returns-1 at the end of the stream +close(: void Closes this input stream and releases any system resources associated with the stream +skip(n: long): long Skips over and discards n characters of data from this input stream The actual number of characters skipped is returned +mark Supported O: boolean Tests if this input stream supports the mark and reset methods +mark(readlimit: int):void Marks the current position in this input stream +reset:void Repositions this stream to the position at the time the mark method was last called on this input stream Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 11 Reader The value is returned as a Unicode. java.io.Reader +read(): int +read(cbuf: char[]): int +read(cbuf: char[], off: int, len: int): int +close(): void +skip(n: long): long +markSupported(): boolean +mark(readlimit: int): void +reset(): void Reads the next character from the input stream. The value returned is an int in the range from 0 to 65535, which represents a Unicode character. Returns -1 at the end of the stream. Reads characters from the input stream into an array. Returns the actual number of characters read. Returns -1 at the end of the stream. Reads characters from the input stream and stores into cbuf[off], cbuf[off+1], …, cbuf[off+len-1]. The actual number of bytes read is returned. Returns -1 at the end of the stream. Closes this input stream and releases any system resources associated with the stream. Skips over and discards n characters of data from this input stream. The actual number of characters skipped is returned. Tests if this input stream supports the mark and reset methods. Marks the current position in this input stream. Repositions this stream to the position at the time the mark method was last called on this input stream
Writer The Unicode value Java.10. writer +write(int c): void Writes the specified character to this output stream. The parameter c is the Unicode for a character +write(cbuf: char[): void Writes all the characters in array cbuf to the output stream +write(cbf charI, off: Writes cbuf[ off], cbuffoff+1),, cbuf offtlen-1] into the output stream int, len: int): void +write(str: String): void Writes the characters from the string into the output stream +write(str: String, off: int, Writes a portion of the string characters into the output stream len: int): void +close(: void Closes this output stream and releases any system resources associated with the stream flush: void Flushes this output stream and forces any buffered output characters to be written Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 12 Writer The Unicode value. java.io.Writer +write(int c): void +write(cbuf: char[]): void +write(cbuf: char[], off: int, len: int): void +write(str: String): void +write(str: String, off: int, len: int): void +close(): void +flush(): void Writes the specified character to this output stream. The parameter c is the Unicode for a character. Writes all the characters in array cbuf to the output stream. Writes cbuf[off], cbuf[off+1], …, cbuf[off+len-1] into the output stream. Writes the characters from the string into the output stream. Writes a portion of the string characters into the output stream. Closes this output stream and releases any system resources associated with the stream. Flushes this output stream and forces any buffered output characters to be written out
File reader/file writer InputStream Reader FileReader Reader Buffered Reader Object Buffered Writer Writer Output Stream Writer File Writer rint Writer File reader/file writer associates an input/output stream with an external file All the methods in file reader/file Writer are inherited from its superclasses Liang, Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 13 FileReader/FileWriter FileReader/FileWriter associates an input/output stream with an external file. All the methods in FileReader/FileWriter are inherited from its superclasses. Reader Writer Object PrintWriter BufferedWriter FileReader FileWriter InputStreamReader BufferedReader OutputStreamWriter
Fi ereader To construct a FileReader, use the following constructors public Filereader(String filename) public Filereader(File file) A java. io FileNotFound Exception would occur if you attempt create a File Reader with a nonexistent file Test Filereader Run Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 14 FileReader To construct a FileReader, use the following constructors: public FileReader(String filename) public FileReader(File file) A java.io.FileNotFoundException would occur if you attempt to create a FileReader with a nonexistent file. TestFileReader Run
File writer To construct a File Writer, use the following constructors public File Writer(String filename) public File Writer(File file) public File Writer(String filename, boolean append) public File Writer(File file, boolean append) If the file does not exist. a new file would be created. If the file already exists, the first two constructors would delete the current contents in the file. To retain the current content and append new data into the file use the last two constructors by passing true to the append parameter TestFilewriter RI un Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 15 FileWriter To construct a FileWriter, use the following constructors: public FileWriter(String filename) public FileWriter(File file) public FileWriter(String filename, boolean append) public FileWriter(File file, boolean append) If the file does not exist, a new file would be created. If the file already exists, the first two constructors would delete the current contents in the file. To retain the current content and append new data into the file, use the last two constructors by passing true to the append parameter. TestFileWriter Run