首页 » 开发 » JAVA » java常用知识:缓冲流的效率测试

java常用知识:缓冲流的效率测试

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package xuexi.heima.Buffered;

import java.io.*;

public class Demo03 {
    public static void main(String[] args) throws IOException {
        Long s = System.currentTimeMillis();
//        FileInputStream fis = new FileInputStream("D:\\javadome\\javaxuexi\\src\\xuexi\\heima\\Buffered\\ceshi\\1.txt");
////        FileOutputStream fos = new FileOutputStream("D:\\javadome\\javaxuexi\\src\\xuexi\\heima\\Buffered\\ceshi\\2.txt");
////        int len = 0;
////        byte[] bytes = new byte[4096000];
////        while((len = fis.read())!=-1){
////            fos.write(len);
////        }
////        fos.close();
////        fis.close();
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("D:\\javadome\\javaxuexi\\src\\xuexi\\heima\\Buffered\\ceshi\\1.txt"));
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("D:\\javadome\\javaxuexi\\src\\xuexi\\heima\\Buffered\\ceshi\\4.txt"));
//        int len = 0;
//        while((len = bis.read())!=-1){
//            bos.write(len);
//        }
        int len =0;
        byte[] bytes = new byte[1024];
        while((len = bis.read(bytes))!=-1){
            bos.write(bytes,0,len);
        }
        bos.close();
        bis.close();

        Long l = System.currentTimeMillis();
        System.out.println(l-s);
    }
}

原文链接:java常用知识:缓冲流的效率测试,转载请注明来源!

0