Import Java.io.BufferedOutputStream;
Import Java.io.DataInputStream;
Import Java.io.DataOutputStream;
Import Java.io.FileInputStream;
Import Java.io.FileOutputStream;
public class StremDemo4 {
public static void Main (string[] args) {
Write ();
Read ();
}
public static void Write () {
try {
The 1.txt file is used as a byte output stream, and the data type of Java can be written directly
/*
* DataOutputStream dos = new DataOutputStream (new
* FileOutputStream ("d:\\1.txt"));
*/
The 1.txt file is used as a byte output stream, and the buffer is written first, and the Java data type can be written directly
/*
* DataOutputStream dos1 = new DataOutputStream (new
* Bufferedoutputstream (New FileOutputStream ("D:\\1.txt"));
*/
//The stream class that discovers the special function has the basic stream flow, nesting constructs, actually is decorates the mode
DataOutputStream dos = new DataOutputStream (New FileOutputStream (
"d:\\ Javalessons\\corejava\\javase-core\\data.txt "));
/*
* If it is fileoutputstream out
* Out.write (10000); The Write method can only write one byte
* But 10000 is 32 bytes, so it will only write after 8 bits
* dataout The Writeint
* method of the Putstream Dos object must be written 4 times per write using the Write method of the Out object
* Writeint internal must be
* Out.write (10000>>24)
* Out.write (10000>>16)
* Out.write (10000>>8)
* Out.write (10000)
*/
Dos.writeint (+);
Dos.writeboolean (TRUE);
Dos.writedouble (10.03);
Dos.writeutf ("HelloWorld");
Dos.close ();
} catch (Exception e) {
E.printstacktrace ();
}
}
public static void Read () {
try {
DataInputStream dis = new DataInputStream (new
FileInputStream ("D:\\javalessons\\corejava\\javase-core\\data.txt"));
/*
* Readint method is used
* InputStream read 4 times and then stitching
* See source code
*/
System.out.println (Dis.readint ());
System.out.println (Dis.readboolean ());
System.out.println (Dis.readdouble ());
System.out.println (Dis.readutf ());
} catch (Exception e) {
E.printstacktrace ();
}
}
}
BYTE Stream DataInputStream