JAva---バッファ入出力ストリームBufferedInputStreamとBufferedOutputStream
1816 ワード
:t1() , ;
1、 buffer buffer
2、buffer
3、 ( Object )
4、 ,
package ThreadIO2_1.IO.buffer;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class BufferedStreamDemo {
public static void main(String[] args) {
try {
//t1();//
//t2();//
//t3();//
} catch (Exception e) {
e.printStackTrace();
}
}
private static void t2() throws Exception {
long t1=System.currentTimeMillis();
DataInputStream din=new DataInputStream(new FileInputStream("b.txt"));
String str=null;
while((str=din.readLine())!=null){
System.out.println(str);
}
long t2=System.currentTimeMillis();
System.out.println(" 2 ( ):"+(t2-t1));
}
private static void t1() throws Exception {
long t1=System.currentTimeMillis();
DataInputStream din=new DataInputStream(new BufferedInputStream(new FileInputStream("b.txt")));
String str=null;
while((str=din.readLine())!=null){
System.out.println(str);
}
long t2=System.currentTimeMillis();
System.out.println(" 1 ( ):"+(t2-t1));
}
private static void t3() throws Exception {
long t1=System.currentTimeMillis();
BufferedInputStream bin=new BufferedInputStream(new DataInputStream(new FileInputStream("b.txt")));
byte[] buf=new byte[20];
int n=0;
while ((n = bin.read(buf)) != -1) {
System.out.println(new String(buf,0,n));
}
long t2 = System.currentTimeMillis();
System.out.println(" 3 ( ):" + (t2 - t1));
}
}