六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 69|回复: 0

javaIO简单总结

[复制链接]

升级  2%

13

主题

13

主题

13

主题

秀才

Rank: 2

积分
53
 楼主| 发表于 2013-1-15 08:17:05 | 显示全部楼层 |阅读模式
使用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));

}
}
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表