Optional InputStreamReader/OutputStream Writer(D InputStreamReader File reader Reader Buffered Reader Object Buffered writer Writer OutputStream Writer File writer Print writer All the methods in InputStreamReader/OutputStream Writer are inherited from Reader/Writer except getEncodingo, which returns the name of encoding being used by this stream Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 16 InputStreamReader/OutputStreamWriter Optional Reader Writer Object PrintWriter BufferedWriter FileReader FileWriter InputStreamReader BufferedReader OutputStreamWriter All the methods in InputStreamReader/OutputStreamWriter are inherited from Reader/Writer except getEncoding(), which returns the name of encoding being used by this stream
Optional InputStreamReader/Output Stream Writer(e InputStreamReader/OutputStream Writer are used to convert between bytes and characters Characters written to an OutputStreamwriter are encoded into bytes using a specified encoding scheme. Bytes read from an InputStreamReader are decoded into characters using a specified encoding scheme. You can specify an encoding scheme using a constructor of InputStreamReader/OutputStream Writer. If no encoding scheme is specified the systems default encoding scheme is used Program A character is converted into the unicode The Unicode of the character is returned A character stored in The Unicode of specified encoding the character is sent out a character is converted into the code for the specified encoding Liang, Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 17 InputStreamReader/OutputStreamWriter InputStreamReader/OutputStreamWriter are used to convert between bytes and characters. Characters written to an OutputStreamWriter are encoded into bytes using a specified encoding scheme. Bytes read from an InputStreamReader are decoded into characters using a specified encoding scheme. You can specify an encoding scheme using a constructor of InputStreamReader/OutputStreamWriter. If no encoding scheme is specified, the system’s default encoding scheme is used. Optional Program The Unicode of the character is returned A character is converted into the Unicode The Unicode of the character is sent out A character stored in a specified encoding A character is converted into the code for the specified encoding
Buffered Reader/Buffered writer Inputstream Reader File reader Reader Buffered Reader Object Buffered writer Writer OutputStream Writer File writer Print writer The buffered stream classes inherit methods from their superclasses. In addition to using the methods from their superclasses. BufferedReader has a readLinea method to read a line, and BufferedWriter has a newLine( method to write a line separator. If the end of stream is reached readLine( returns nul Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 18 BufferedReader/BufferedWriter Reader Writer Object PrintWriter BufferedWriter FileReader FileWriter InputStreamReader BufferedReader OutputStreamWriter The buffered stream classes inherit methods from their superclasses. In addition to using the methods from their superclasses, BufferedReader has a readLine() method to read a line, and BufferedWriter has a newLine() method to write a line separator. If the end of stream is reached, readLine() returns null
Print riter/printstream Inputstream Reader File reader Reader Buffered Reader Object Buffered writer Writer OutputStream Writer File writer i Print Writer Bufferedwriteris used to output characters and strings. PrintWriter and PrintStreamcan be used to output objects, strings and numeric values as text. PrintWriter was introduced in JDK 1. 2 to replace PrintStream both classes are almost identical in the sense that they provide the same function and same methods for outputting strings and numeric values as text. Print Writer is more efficient than Printstream. So, you use Print Writer rather than Printstream Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 19 PrintWriter/PrintStream Reader Writer Object PrintWriter BufferedWriter FileReader FileWriter InputStreamReader BufferedReader OutputStreamWriter BufferedWriteris used to output characters and strings. PrintWriter and PrintStreamcan be used to output objects, strings and numeric values as text. PrintWriterwas introduced in JDK 1.2 to replace PrintStream.Both classes are almost identical in the sense that they provide the same function and same methods for outputting strings and numeric values as text. PrintWriteris more efficient than PrintStream. So, you use PrintWriterrather than PrintStream
Methods in Print Writer/PrintStream public void print(object o) public void printin(object o public void print(String s public void println(String s) public void print (char c) public void println(char c) public void print(char[] cArray public void println(char[ cArray public void print (int i) public void println(int i public void print (long 1) public void println (long 1) public void print(float f) public void println(float f) public void print(double d) public void println (double d) public void print (boolean b) public void println (boolean b) Print Writer and Print Stream also contain the JDK 1. 5 printf method for printing formatted output, which was introduced in Section 2. 17,Formatted Output Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 20 Methods in PrintWriter/PrintStream public void print(Object o) public void print(String s) public void print(char c) public void print(char[] cArray) public void print(int i) public void print(long l) public void print(float f) public void print(double d) public void print(boolean b) public void println(Object o) public void println(String s) public void println(char c) public void println(char[] cArray) public void println(int i) public void println(long l) public void println(float f) public void println(double d) public void println(boolean b) PrintWriter and PrintStream also contain the JDK 1.5 printf method for printing formatted output, which was introduced in Section 2.17, “Formatted Output