IO流(操作基本数据类型的流对象DataStream)

 1 package com.yyq;
 2 import java.io.*;
 3 /*
 4  * DataInputStream 和 DataOutputStream
 5  * 专门操作数据的(基本数据类型)
 6  * 为什么数据显示不清楚,因为记事本显示的是字符
 7  */
 8 public class DataStreamDemo {
 9 
10     public static void main(String[] args) throws IOException {
11         // TODO Auto-generated method stub
12         //writeData();
13         //readData();
14         writeUTF();
15     }
16     public static void readData() throws IOException{
17         DataInputStream dis = new DataInputStream(new FileInputStream("data.txt"));
18         System.out.println(dis.readInt());
19         System.out.println(dis.readBoolean());
20     }
21     public static void writeUTF() throws IOException{
22         DataOutputStream dos = new DataOutputStream(new FileOutputStream("utfdata.txt"));
23         dos.writeUTF("你好");
24         dos.flush();
25         dos.close();
26     }
27     public static void writeData() throws IOException{
28         DataOutputStream dos = new DataOutputStream(new FileOutputStream("data.txt"));
29         dos.writeInt(234);
30         dos.writeBoolean(true);
31         dos.writeDouble(123.123);
32         dos.close();
33     }
34 
35 }

 

posted @ 2016-01-24 20:13  HuberyQian  阅读(421)  评论(0编辑  收藏  举报