黑马程序员技术交流社区

标题: 一次复制一个字节数组 [打印本页]

作者: China_Riven    时间: 2015-7-16 13:21
标题: 一次复制一个字节数组
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class Democopy2 {

        /**
         * 一次复制一个字节数组
         * @param args
         * @throws IOException
         */
        public static void main(String[] args) throws IOException {
                // TODO Auto-generated method stub
               
                //创建流对象
                //读
                //每次读到的字节个数
                //写
                //关闭流
                method2();
        }
  public static void method2() throws IOException{
        //创建流对象
          FileInputStream  fis =  new FileInputStream("src\\dema.txt");
          FileOutputStream  fos = new FileOutputStream("src\\riven.txt");
          //读
          int len;
          byte [] bytes = new byte[1024];
          while((len= fis.read(bytes))!=-1){
                  fos.write(bytes, 0, len);
          }
          fis.close();
          fos.close();
  }
}





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