黑马程序员技术交流社区

标题: IO流 [打印本页]

作者: nc11111    时间: 2016-4-8 23:38
标题: IO流
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 这个方法是什么 时候用呢?
作者: 荒丶    时间: 2016-4-8 23:46
public void write(byte[] b, int off, int len)  这个方法看你什么需求了  .因为第二个参数是从缓冲流的第几个字节开始读起
作者: nc11111    时间: 2016-4-13 22:46
看了一会API,已经了解了,谢谢了





欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2