A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 蓁蓁丶 中级黑马   /  2016-3-18 17:51  /  547 人查看  /  2 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文



        /**
         * @param args
         * @throws IOException
         */
        public static void main(String[] args) throws IOException {
                //demo();
                //demo1();
                //demo2();
                long st =System.currentTimeMillis();
                BufferedInputStream bis = new BufferedInputStream(new FileInputStream("20.01_IO流(IO流概述及其分类).avi"));
                BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("练习.avi"));
                int len ;
                while((len = bis.read()) != -1){
                        bos.write(len);
                }
                bis.close();
                bos.close();
                long ts = System.currentTimeMillis();
                System.out.println(st-ts);
               
        }

        public static void demo2() throws FileNotFoundException, IOException {
                FileInputStream fil = new FileInputStream("20.01_IO流(IO流概述及其分类).avi");
                FileOutputStream fos = new FileOutputStream("练习.avi");
                byte[]arr = new byte[8192];
                int len;
                while((len = fil.read(arr)) != -1){
                        fos.write(arr, 0, len);
                       
                }
               
                fil.close();
                fos.close();
               
        }

        public static void demo1() throws FileNotFoundException, IOException {
                FileInputStream fil = new FileInputStream("xxx.txt");
                FileOutputStream fos = new FileOutputStream("zzz.txt");
                byte[] arr = new byte[2];
                int len;
                while((len=fil.read(arr)) != -1){
                        fos.write(arr, 0, len);
                }
                fil.close();
                fos.close();
        }

        public static void demo() throws FileNotFoundException, IOException {
                FileInputStream fil = new FileInputStream("zzz.tst");
                FileOutputStream fos  = new FileOutputStream("copy.txt");
                byte[] arr = new byte[fil.available()] ;
                /*while((i=fil.read())!=-1){
                        fos.write(i);
                }*/
                fil.read(arr);
                fos.write(arr);
                fil.close();
                fos.close();
        }

评分

参与人数 1黑马币 +20 收起 理由
何毅 + 20 神马都是浮云

查看全部评分

2 个回复

倒序浏览
同志还需努力
回复 使用道具 举报
刚开课,还没学到,路过帮顶....
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马