DataStream_基本タイプのデータを操作するストリーム・オブジェクト

3607 ワード

 1 import java.io.DataInputStream;

 2 import java.io.DataOutputStream;

 3 import java.io.FileInputStream;

 4 import java.io.FileOutputStream;

 5 import java.io.IOException;

 6 

 7 public class Test {

 8     public static void main(String[] args) throws IOException {

 9         writeData();

10         readData();

11     }

12     public static void readData() throws IOException {

13         

14         DataInputStream dis = new DataInputStream(new FileInputStream("F:\\IO\\data.txt"));

15         

16         String str = dis.readUTF();

17         

18         System.out.println(str);

19     }

20 

21     public static void writeData() throws IOException {

22         

23         DataOutputStream dos = new DataOutputStream(new FileOutputStream("F:\\IO\\data.txt"));

24         

25         dos.writeUTF(" ");

26         

27         dos.close();

28     }

29 }