package cn.stat.p2.demo; import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException; public class datastreamdemo { /**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
//DataInputStream与DataOutputStream写入数据的同时写入数据类型
writedata();
readdata();
} public static void readdata() throws IOException {
DataInputStream dis=new DataInputStream(new FileInputStream("data.txt"));
String str=dis.readUTF();
System.out.println(str); } public static void writedata() throws IOException { DataOutputStream dos=new DataOutputStream(new FileOutputStream("data.txt"));
dos.writeUTF("你好");
dos.close(); } }