写入数据
@Test public void test10() throws IOException { DataOutputStream dos = new DataOutputStream(new FileOutputStream("data.txt")); dos.writeUTF("猪八戒"); dos.writeInt(26); dos.writeBoolean(true); dos.close(); }
读取数据
@Test public void test11() throws IOException { DataInputStream dis = new DataInputStream(new FileInputStream("data.txt")); String name = dis.readUTF(); int age = dis.readInt(); boolean isMale = dis.readBoolean(); System.out.println("name = " + name); System.out.println("age = " + age); System.out.println("isMale = " + isMale); dis.close(); }