如何从头到尾读取文件? [英] How to read a file from end to the beginning?

查看:126
本文介绍了如何从头到尾读取文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从头到尾读取文件我的代码,

How to read file from end to the beginning my code,

  try                
   {
      String strpath="/var/date.log";
      FileReader fr = new FileReader(strpath);
      BufferedReader br = new BufferedReader(fr);
      String ch;
      String[] Arr;
      do 
      {
        ch = br.readLine();
        if (ch != null)
        out.print(ch+"<br/>");   
      } 
      while (ch != null);
      fr.close();
    }
    catch(IOException e){
    out.print(e.getMessage());
  }


推荐答案

您可以使用RandomAccessFile类。要么只是从文件长度读取循环到0,要么使用一些方便的第三方包装,如 http://mattfleming.com/ node / 11

You can use RandomAccessFile class. Either just read in loop from file length to 0, or use some convenience 3rd party wraps like http://mattfleming.com/node/11

这篇关于如何从头到尾读取文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆