package test.stream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* 读写字节数据,过滤流
* @author Frost.Yen
* @E-mail 871979853@qq.com
* @date 2016年4月13日
*/
public class TestWriteData02 {
public static void main(String[] args) {
FileOutputStream fos = null;
DataOutputStream dos = null;
DataInputStream dis = null;
try {
fos = new FileOutputStream("E:\\JAVA\\Examples\\To Learn\\src\\test\\stream\\data1.dat");
//如果希望存储基本数据类型就使用DataOutputStream,也是过滤流
dos = new DataOutputStream(fos);
dos.writeInt(121245678);
dos.writeInt(15678);
dos.writeInt(1215678);
dos.writeInt(121245678);
dos.writeInt(15678);
dos.writeInt(121245374);
//从文件读取基本数据类型使用DataInputStream,也是过滤流
dis = new DataInputStream(new FileInputStream("E:\\JAVA\\Examples\\To Learn\\src\\test\\stream\\data1.dat"));
int a = dis.readInt();
System.out.println(a);
System.out.println(dis.readInt());
System.out.println(dis.readLong());
System.out.println(dis.readInt());
System.out.println(dis.readInt());
//System.out.println(dis.readInt());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally {
try {
if(dos!=null) dos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}