怎样使用BufferedReader的readLine()读取某个文件的的指定行?

crazy_he 2006-02-08 10:14:11
我的部分代码为
String line = null;
while (((line = in.readLine())!= null)) {
out.print(line);
}

比如我只要读取文件的部分行,从第11-99行,应该怎么写??
...全文
2168 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
christion3 2006-02-08
  • 打赏
  • 举报
回复
能不能和SQL里分页一样来读TOP10条记录啊
bevin1010 2006-02-08
  • 打赏
  • 举报
回复
BufferedReader can not reading by specified line number! it reads file from begin to end , you can use RandomAccessFile
crazy_he 2006-02-08
  • 打赏
  • 举报
回复
有没有代价小一点的方法?

楼上的方法可行,但是万一文件大了开销就大了
wangx1949 2006-02-08
  • 打赏
  • 举报
回复
没有相关函数,只能不断调用readLine()来控制.
票票飞扬 2006-02-08
  • 打赏
  • 举报
回复
String line = null;
int iBegin = 11, iEnd = 99;
int iLine = 1;
while (((line = in.readLine())!= null)) {
if (iLine>=iBegin && iLine<=iEnd){
out.print(line);
}
iLine++;
}

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧