好好学一下装饰模式就好了,Sysout.out实际上是一个输出流,缓冲流包装一个输出流很正常啊,至于你说的那个桥梁就是把它转化为字节流了啊下面是我学习室写的程序
package io;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
public class DataOutputStreamtest1 {
public static void main(String[] args) throws IOException {
DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("f:/java.txt")));//装饰模式
byte b = 3;
int a = 5;
float fl = 1.49f;
boolean bo = false;
dos.write(b);
//dos.write(a);
dos.writeInt(a);
dos.writeFloat(fl);
dos.writeBoolean(bo);
dos.close();
InputStream is = new FileInputStream("f:/java.txt");
int length ;
byte[] buffer = new byte[300];
if(-1!= (length = is.read(buffer,0,300)));
String str = new String(buffer,0,length);
System.out.println(str);
is.close();
//读和写的顺序一定要保持严格一致
DataInputStream dis = new DataInputStream(new BufferedInputStream(new FileInputStream("f:/java.txt")));
System.out.println(dis.readByte());
System.out.println(dis.readInt());
System.out.println(dis.readFloat());
System.out.println(dis.readBoolean());
dis.close();
}
}
|