java DataInputStream和DataOutputStream詳解
操作基本數(shù)據(jù)類型的流
DataInputStream
DataOutputStream
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; public class IntegerDemo { public static void main(String[] args) throws IOException { myWrite(); myReader(); } private static void myWrite() throws IOException { // TODO Auto-generated method stub // 創(chuàng)建數(shù)據(jù)輸出流對(duì)象 FileOutputStream fos = new FileOutputStream( "E:\\zikao\\file\\cs.txt" ); DataOutputStream dos = new DataOutputStream(fos); // 寫數(shù)據(jù) dos.writeByte( 10 ); dos.writeShort( 100 ); dos.writeInt( 1000 ); dos.writeLong( 10000 ); dos.writeFloat( 12 .34F); dos.writeDouble( 12.56 ); dos.writeChar( 'a' ); dos.writeBoolean( true ); // 釋放資源 dos.close(); } private static void myReader() throws IOException { // TODO Auto-generated method stub // 創(chuàng)建數(shù)據(jù)輸入流對(duì)象 FileInputStream fis = new FileInputStream( "E:\\zikao\\file\\cs.txt" ); DataInputStream dis = new DataInputStream(fis); // 讀數(shù)據(jù) byte b = dis.readByte(); short s = dis.readShort(); int i = dis.readInt(); long l = dis.readLong(); float f = dis.readFloat(); double d = dis.readDouble(); char c = dis.readChar(); boolean bl = dis.readBoolean(); // 釋放資源 dis.close(); System.out.println(b); System.out.println(s); System.out.println(i); System.out.println(l); System.out.println(f); System.out.println(d); System.out.println(c); System.out.println(bl); } } |
感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!