黑马程序员技术交流社区

标题: 突然很茫然啊 [打印本页]

作者: 蓁蓁丶    时间: 2016-3-18 17:51
标题: 突然很茫然啊


        /**
         * @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();
        }

作者: 何毅    时间: 2016-3-18 17:52
同志还需努力
作者: Liu15192609783    时间: 2016-3-18 22:12
刚开课,还没学到,路过帮顶....




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