美文网首页
字节流和字节缓冲流的速度对比

字节流和字节缓冲流的速度对比

作者: 眼若繁星丶 | 来源:发表于2020-09-26 12:00 被阅读0次

    字节流和字节缓冲流的速度对比


    import java.io.*;
    
    /*
        1.基本字节流一次读写一个字节         //共耗时:756270 ms
        2。基本字节流一次读写一个字节数组      //共耗时:1071 ms
        3..字节缓冲流一次读写一个字节        // 共耗时:2732 ms
        4.字节缓冲流一次读写一个数组         // 共耗时:210 ms
     */
    public class CopyAviDemo {
        public static void main(String[] args) throws IOException {
            long start = System.currentTimeMillis();
    
    //        method1();
    //        method2();
    //        mathod3();
    //        mathod4();
    
            long end = System.currentTimeMillis();
            System.out.println("共耗时:" + (end - start) + " ms");
        }
    
        private static void method1() throws IOException {
            FileInputStream fis = new FileInputStream("E:\\哔哩哔哩视频\\75918025\\1\\75918025_1_0.flv");
            FileOutputStream fos = new FileOutputStream("C:\\Users\\10270\\Desktop\\1.avi");
            int by;
            while ((by = fis.read()) != -1) {
                fos.write(by);
            }
            fis.close();
            fos.close();
        }
    
        private static void method2() throws IOException {
            FileInputStream fis = new FileInputStream("E:\\哔哩哔哩视频\\75918025\\1\\75918025_1_0.flv");
            FileOutputStream fos = new FileOutputStream("C:\\Users\\10270\\Desktop\\2.avi");
            int len;
            byte[] bys = new byte[1024];
            while ((len = fis.read(bys)) != -1) {
                fos.write(bys, 0, len);
            }
            fis.close();
            fos.close();
        }
    
        private static void mathod3() throws IOException {
            BufferedInputStream bis = new BufferedInputStream(new FileInputStream("E:\\哔哩哔哩视频\\75918025\\1\\75918025_1_0.flv"));
            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("C:\\Users\\10270\\Desktop\\3.avi)"));
    
            int by;
            while ((by = bis.read()) != -1) {
                bos.write(by);
            }
            bis.close();
            bos.close();
        }
    
        private static void mathod4() throws IOException {
            BufferedInputStream bis = new BufferedInputStream(new FileInputStream("E:\\哔哩哔哩视频\\75918025\\1\\75918025_1_0.flv"));
            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("C:\\Users\\10270\\Desktop\\4.avi"));
    
            int len;
            byte[] bys = new byte[1024];
            while ((len = bis.read(bys)) != -1) {
                bos.write(bys, 0, len);
            }
            bis.close();
            bos.close();
        }
    }
    

    相关文章

      网友评论

          本文标题:字节流和字节缓冲流的速度对比

          本文链接:https://www.haomeiwen.com/subject/xuecuktx.html