static void read1() throws IOException {
// read bytes from the file one at a time
MyTimer mt = new MyTimer();
FileInputStream fis =
new FileInputStream(TESTFILE);
cnt1 = 0;
int c;
while ((c = fis.read()) != -1) {
if (c == 'A') {
cnt1++;
}
}
fis.close();
System.out.println("read1 time = " +
mt.getElapsed());
}
static void read2() throws IOException {
// read bytes from the file one at a time
// with buffering
MyTimer mt = new MyTimer();
FileInputStream fis =
new FileInputStream(TESTFILE);
BufferedInputStream bis =
new BufferedInputStream(fis);
cnt2 = 0;
int c;
while ((c = bis.read()) != -1) {
if (c == 'A') {
cnt2++;
}
}
fis.close();
System.out.println("read2 time = " +
mt.getElapsed());
}
static void read3() throws IOException {
// read from the file with buffering
// and with direct access to the buffer
MyTimer mt = new MyTimer();
FileInputStream fis =
new FileInputStream(TESTFILE);
cnt3 = 0;
final int BUFSIZE = 1024;
byte buf[] = new byte[BUFSIZE];
int len;
while ((len = fis.read(buf)) != -1) {
for (int i = 0; i < len; i++) {
if (buf[i] == 'A') {
cnt3++;
}
}
}
fis.close();
System.out.println("read3 time = "
+ mt.getElapsed());
}
// read bytes from the file one at a time
MyTimer mt = new MyTimer();
FileInputStream fis =
new FileInputStream(TESTFILE);
cnt1 = 0;
int c;
while ((c = fis.read()) != -1) {
if (c == 'A') {
cnt1++;
}
}
fis.close();
System.out.println("read1 time = " +
mt.getElapsed());
}
static void read2() throws IOException {
// read bytes from the file one at a time
// with buffering
MyTimer mt = new MyTimer();
FileInputStream fis =
new FileInputStream(TESTFILE);
BufferedInputStream bis =
new BufferedInputStream(fis);
cnt2 = 0;
int c;
while ((c = bis.read()) != -1) {
if (c == 'A') {
cnt2++;
}
}
fis.close();
System.out.println("read2 time = " +
mt.getElapsed());
}
static void read3() throws IOException {
// read from the file with buffering
// and with direct access to the buffer
MyTimer mt = new MyTimer();
FileInputStream fis =
new FileInputStream(TESTFILE);
cnt3 = 0;
final int BUFSIZE = 1024;
byte buf[] = new byte[BUFSIZE];
int len;
while ((len = fis.read(buf)) != -1) {
for (int i = 0; i < len; i++) {
if (buf[i] == 'A') {
cnt3++;
}
}
}
fis.close();
System.out.println("read3 time = "
+ mt.getElapsed());
}
解决方案 »
- java 同步
- java -cp 和java -classpath有什么区别?
- 郁闷~自考教材找不到学校给的电子文档让我们学习,马上要考试了求个JAVA最基础的试题,谢谢~~
- 输入一个日期判断是星期几,要判断输入的字符是否合法,输入一个或多个空格空格也有提示错误,然后请用户重新输入。
- 急!!!求助java语音聊天
- 出什么问题了??
- 关于ServerSocket收到包处理的问题!!
- 请问:NMS/OSS, SONET, MPLS and GbE 这些都是什么???
- 各位大哥我用Jbuilder打包application的jar文件怎样才能运行?谢谢了!
- 为什么我买的正版《大本营Java》不能下载新的数据库文件啊??????
- 寻求JB8+Weblogic7的配置!
- 关于Java开发工具
readLine():是BufferedReader的方法,读一个以'\r'或'\n'结尾的串,如果到达末尾,则返回null
read():读一个字符,如果到达stream末尾,则返回-1
readLine():是BufferedReader的方法,读一个以'\r'或'\n'结尾的串,如果到达末尾,则返回null补充:我们可以单从意思上理解,readline,就是都一行,而每一行的结尾一般都是以"\n"结束的===================================
情人节快乐
有情人终成眷属
我的一分耕耘,你能给一分收获