package test01;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class DemobafferdStream {
public static void main(String[] args) throws IOException {
BufferedOutputStream bo = new BufferedOutputStream(new FileOutputStream("G:\\c.txt"));
BufferedInputStream bi = new BufferedInputStream(new FileInputStream("G:\\b.txt"));
int i;
byte[] bs = new byte[1024];
while ((i = bi.read(bs)) != -1) {
bo.write(bs);
String string = new String(bs, 0, i);
System.out.println(string);
}
bo.close();
bi.close();
}
}
这个是缓冲字节流,先读取("G:\\b.txt")文件,然后输出("G:\\c.txt")文件。
问:能不能先用缓冲输出流写文件,用缓冲输入流写到另一个文件呢?
public void write(byte[] b, int off, int len) throws IOException 这个方法是什么 时候用呢? |
|