本帖最后由 涐扪①起奮乧 于 2013-12-15 13:33 编辑
- package cn.itcast;
- import java.io.DataInputStream;
- import java.io.DataOutputStream;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- public class DataDemo
- {
- public static void main(String[] args) throws IOException
- {
- readData();
- //writeData();
- }
- public static void readData()throws IOException
- {
- //创建DataInputStream对象并传入一个写入流
- DataInputStream dis = new DataInputStream(new FileInputStream("E:\\data.txt"));
- int num = dis.readInt();
- boolean b = dis.readBoolean();
- double d = dis.readDouble();
- sop("num="+num);
- sop("b="+b);
- sop("d="+d);
- dis.close();
- }
- public static void writeData()throws IOException
- {
- DataOutputStream dos = new DataOutputStream(new FileOutputStream("E:\\data.txt"));
- dos.write(234);
- dos.writeBoolean(true);
- dos.writeDouble(100.876);
- dos.close();
- }
- public static void sop(Object obj)
- {
- System.out.println(obj);
- }
- }
复制代码 写入成功如下图:
但是读取失败:
|
|