Conversion Flow:
InputStreamReader and OutputStreamWriter are used for conversion between byte data and character data.
InputStreamReader needs to be inputstream with the socket.
OutputStreamWriter needs to be outputstream with the socket.
A transform stream can specify its encoding collection at construction time.
Import java.io.*;p ublic class Testtransform1{public static void Main (string[] args) {Try{outputstreamwriter osw= New OutputStreamWriter (//character stream flows to the bridge of the byte stream new FileOutputStream ("D:\\bak\\char.txt"));//file output stream is used to write data to file or FileDescriptor output stream Osw.write ("Microsoft IBMSUNAPPLEHP"); System.out.println (Osw.getencoding ()); Osw.close (); osw=new OutputStreamWriter (New FileOutputStream ("d:\\bak\\ Char.txt ", True)," iso8859_1 "); Osw.write (" Microsoft IBMSUNAPPLEHP "); System.out.println (Osw.getencoding ());//Returns the name of the character encoding used by this stream. Osw.close ();} catch (IOException e) {e.printstacktrace ();//print out exceptions and deeper invocation information. }}}
Import java.io.*;p ublic class testtransform2{public static void Main (string[] args) {InputStreamReader isr=new InputStreamReader (system.in); BufferedReader br=new BufferedReader (ISR); String S=null;try{s=br.readline ();//Enter a number while (S!=null) {if (S.equalsignorecase ("Exit")) break;//this String with another String comparison, regardless of case System.out.println (S.touppercase ());//Use the default locale rule to convert all characters in this String to uppercase. S=br.readline ();// reads a line of text. }br.close ();} catch (IOException e) {e.printstacktrace ();//print out all the call conditions and error messages}}}
Data flow:
DataInputStream and DataOutputStream inherit from InputStream and OutputStream respectively, and it belongs to the processing stream. Need to be nested on InputStream and outputstream types of node streams.
DataInputStream and DataOutputStream provide a way to access the machine-independent Java primitive type data.
Import java.io.*;p ublic class testdatastream{public static void Main (string[] args) {Bytearrayoutputstream baos=new Bytearrayoutputstream ();//This class implements an output stream in which the data is written to a byte array//Creates a new data output stream and writes the data to the specified underlying output stream. DataOutputStream dos=new DataOutputStream (BAOs); Try{dos.writedouble (Math.random ());d Os.writeboolean (true); Bytearrayinputstream bais=new Bytearrayinputstream (Baos.tobytearray ()); System.out.println (Bais.available ());D atainputstream dis=new datainputstream (Bais); System.out.println (Dis.readdouble ()); System.out.println (Dis.readboolean ());d os.close ();d is.close (); catch (IOException e) {e.printstacktrace ();}}}
Io stream demo--"J2SE"