本帖最后由 思维 于 2014-8-27 23:03 编辑
今天写了个操作基本数据类型的输入流和输出流谁来分析下原因啊?读取的时候故意打乱读取顺序,为什么得不到正确的结果?
- import java.io.*;
- class DataStream{
- public static void main(String[] args)throws IOException{
- //writeData();
- readData();
- }
- private static void writeData()throws IOException{
- DataOutputStream dos = new DataOutputStream(new FileOutputStream("data.txt"));
- dos.writeInt(123456);
- dos.writeInt(123456);
- dos.writeBoolean(false);
- dos.writeInt(123456);
- dos.close();
- }
- private static void readData()throws IOException{
- DataInputStream dis = new DataInputStream(new FileInputStream("data.txt"));
- System.out.println(dis.readInt());
- System.out.println(dis.readBoolean());
- System.out.println(dis.readInt());
- System.out.println(dis.readInt());
- dis.close();
- }
- }
复制代码
|
|