java--reads the contents of the file to the basic data type and string

Source: Internet
Author: User

writes the basic type data to the file, then reads it
 Packagecom.machuang.io.others;ImportJava.io.BufferedInputStream;ImportJava.io.BufferedOutputStream;ImportJava.io.DataInputStream;ImportJava.io.DataOutputStream;ImportJava.io.FileInputStream;ImportJava.io.FileOutputStream;Importjava.io.IOException; Public classDataStream { Public Static voidMain (string[] args)throwsIOException {String path= "F:/win10/test/data.txt";                Writebasictypes (path); //Connect to the file you want to readDataInputStream dis =NewDataInputStream (NewBufferedinputstream (NewFileInputStream (path)); //Read Operations        DoubleRecdou =dis.readdouble (); LongRECL =Dis.readlong (); String RecS=Dis.readutf (); System.out.println ("Recdou:\t" + Recdou + "\ n" + "recl:\t" + recl + "\ n" + "recs:\t" +RecS);            Dis.close (); }     Public Static voidWritebasictypes (String Despath)throwsIOException {//the data to be written        DoubleDatadou = 3.6; LongNUML = 100L; String Datastr= "Architecture"; //Associate a file written outDataOutputStream dos =NewDataOutputStream (NewBufferedoutputstream (NewFileOutputStream (Despath))        );        Dos.writedouble (Datadou);        Dos.writelong (NUML);                Dos.writeutf (DATASTR);        Dos.flush ();                    Dos.close (); }        }

The operation results are as follows

java--reads the contents of the file to the basic data type and string

Related Article

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.