BYTE Stream DataInputStream

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.