package com.ffyc.javaio.file;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Calendar;
import java.util.Date;
public class StreamDemo {
public static void main(String[] args) throws IOException {
/*
write()和read()
*/
long b1 = new Date().getTime();
FileInputStream f = new FileInputStream("C:/kms10.log");
FileOutputStream f1 = new FileOutputStream("D:/demo1.txt");
int a = 0;
while((a =f.read())!=-1){
f1.write(a);
}
f.close();
f1.close();
long b2 = Calendar.getInstance().getTimeInMillis();
System.out.println(b2-b1);
/*
write(byte[] b,int off,int length)和read(byte[] b)
*/
long c1 = new Date().getTime();
FileInputStream f2 = new FileInputStream("C:/kms10.log");
FileOutputStream f3 = new FileOutputStream("D:/demo6.txt");
byte []d = new byte[100];
int size = 0;
while((size = f2.read(d))!=-1){
f3.write(d,0,size);
}
f2.close();
f3.close();
long c2 = Calendar.getInstance().getTimeInMillis();
System.out.println(c2-c1);
}
}
(java)测试字节流read(),read(byte[] b) 和两个write(),write(byte[] b,int off,int length)的读写速度.
最新推荐文章于 2024-07-17 17:53:42 发布