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