package testIO;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
public class Demo1 {
public static void main(String[] args) {
try {
long startTime=System.currentTimeMillis();//开始时间
//1.铺设管道
InputStream file=new FileInputStream("E:\\2021.txt");
BufferedInputStream f=new BufferedInputStream(file);
//2.开水龙头--先创建一辆小车
byte[] car=new byte[1024];
int len=0;
while((len=f.read(car))!=-1){
System.out.println(len);
}
//3.关流
f.close();
long endTime=System.currentTimeMillis();//结束时间
System.out.println("共耗时"+(endTime-startTime)+"毫秒");
} catch (Exception e) {
e.printStackTrace();
}
}
}
测试BufferedOutputStream写速度:
package testIO;
import java.io.*;
public class Demo1 {
public static void main(String[] args) {
try {
long startTime=System.currentTimeMillis();//开始时间
//1.铺设管道
InputStream file=new FileInputStream("E:\\1998.txt");
BufferedInputStream f=new BufferedInputStream(file);
OutputStream file2=new FileOutputStream("E:\\2021.txt");
BufferedOutputStream os=new BufferedOutputStream(file2);
//2.开水龙头--先创建一辆小车
byte[] car=new byte[1024];
int len=0;
while((len=f.read(car))!=-1){
os.write(car,0,len);
}
//3.关流
f.close();
os.close();
long endTime=System.currentTimeMillis();//结束时间
System.out.println("共耗时"+(endTime-startTime)+"毫秒");
} catch (Exception e) {
e.printStackTrace();
}
}
}
BufferedInputStream-BufferedOutputStream