javaIO简单总结

使用buffer 在外面 速度慢 这里又要分(文件流,字符流,字节流)
使用buffer 在中间 速度快 这里又要分(文件流,字符流,字节流)
没有是使用buffer 速度最慢
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class DataOutputStreamTest {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
long t1 = System.currentTimeMillis();
try {
DataInputStream dos=new DataInputStream(
new BufferedInputStream(new FileInputStream("src/bb.txt"))
);
// BufferedInputStream bufferedInputStream = new BufferedInputStream(
// new DataInputStream(new FileInputStream("src/bb.txt")));
// byte bs[]=new byte[bufferedInputStream.available()];
// bufferedInputStream.read(bs,0,bs.length);
// bufferedInputStream.close();
// System.out.println(new String(bs));///total==14904
// String string = null;
// while ((string = dos.readLine()) != null) {
// System.out.println(string);
// }//total==13812
System.out.println(dos.readUTF());//total==15
dos.close();

} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
long t2 = System.currentTimeMillis();
System.out.println("total==" + (t2 - t1));

}
}

你可能感兴趣的:(java,dos)