1. Basic Concepts DataOutputStream data output stream allows applications to write Basic Java data types to the output stream in an appropriate way. Then the application can use the data input stream to read data. The DataOutputStream data input stream allows applications to read Basic Java data types from the underlying input stream in a machine-independent manner. Applications can use the data output stream to write data that is later read by the data input stream. Multi-threaded access is not necessarily safe. Thread security is optional and is the responsibility of the user of such methods. 2. For the example [java]/***, you must first use DataOutputStream to write data and then use DataInputStream to read data. ** @ Author Xu Yue **/public class TestClass {public static void main (String [] args) throws Exception {TestClass t = new TestClass (); t. write (); t. read ();} public void write () throws Exception {String path = this. getClass (). getClassLoader (). getResource ("test.txt "). toURI (). getPath (); OutputStream OS = new FileOutputStream (path); DataOutputStream dos = new DataOutputStream (OS); dos. writeDouble (Mat H. random (); dos. writeBoolean (true); dos. writeInt (1, 1000); dos. writeInt (1, 2000); dos. flush (); OS. close (); dos. close ();} public void read () throws Exception {InputStream instream = this. getClass (). getClassLoader (). getResourceAsStream ("test.txt"); DataInputStream dis = new DataInputStream (instream); double d = dis. readDouble (); boolean B = dis. readBoolean (); // first read the int i1 = dis. readInt (); int i2 = Dis. readInt (); instream. close (); dis. close (); System. out. println (d); System. out. println (B); System. out. println (i1); System. out. println (i2) ;}}/*** must first use DataOutputStream to write data and then use DataInputStream to read data. ** @ Author Xu Yue **/public class TestClass {public static void main (String [] args) throws Exception {TestClass t = new TestClass (); t. write (); t. read ();} public void write () throws Exception {String path = this. getClass (). getClassLoader (). getResource ("test.txt "). toURI (). getPath (); OutputStream OS = new FileOutputStream (path); DataOutputStream dos = new DataOutputStream (OS); dos. writeDouble (Math. random (); dos. writeBoolean (true); dos. writeInt (1, 1000); dos. writeInt (1, 2000); dos. flush (); OS. close (); dos. close ();} public void read () throws Exception {InputStream instream = this. getClass (). getClassLoader (). getResourceAsStream ("test.txt"); DataInputStream dis = new DataInputStream (instream); double d = dis. readDouble (); boolean B = dis. readBoolean (); // first read the int i1 = dis. readInt (); int i2 = dis. readInt (); instream. close (); dis. close (); System. out. println (d); System. out. println (B); System. out. println (i1); System. out. println (i2) ;}} output result 0.4683894257027681true10002000