解决方案 »

  1.   

    LineNumberInputStream 
    LineNumberReader 
    额这两个类试试看
      

  2.   

    LineNumberReader lnr = new LineNumberReader(new InputStreamReader(formFile.getInputStream()));  
    lnr.skip(formFile.getFileSize());  
    lnr.getLineNumber() 然后读取试试看
      

  3.   

    public static void main(String[] args) throws Exception {
    File file = new File("c:/data.txt"); BufferedReader br = new BufferedReader(new FileReader(file)); String buf = null;
    String str = null; if (file.length() > 1024 * 1024 * 1024) {
    br.skip(file.length() / 3 * 2);// 当文件超过1M大小的时候,跳过文本长度的2/3,具体跳过多少视实际情况而定,文件越大可以跳过的部分越多
    } while ((buf = br.readLine()) != null) {
    str = buf;
    } br.close(); System.out.println(str);
    }
      

  4.   

    见3#,前面那2个类查了下api就是扯淡的
      

  5.   

    简单的定时任务可以用Timerpublic static void main(String[] args) throws Exception { Timer timer = new Timer(); timer.schedule(new TimerTask() {
    public void run() {
    try {
    File file = new File("c:/data.txt"); BufferedReader br = new BufferedReader(new FileReader(file)); String buf = null;
    String str = null; if (file.length() > 1024 * 1024 * 1024) {
    br.skip(file.length() / 3 * 2);// 当文件超过1M大小的时候,跳过文本长度的2/3,具体跳过多少视实际情况而定,文件越大可以跳过的部分越多
    } while ((buf = br.readLine()) != null) {
    str = buf;
    } br.close(); System.out.println(str);
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    }, 0, 5000);
    }
      

  6.   

    public static String readLastLine(File file, String charset) throws IOException {  
      if (!file.exists() || file.isDirectory() || !file.canRead()) {  
        return null;  
      }  
      RandomAccessFile raf = null;  
      try {  
        raf = new RandomAccessFile(file, "r");  
        long len = raf.length();  
        if (len == 0L) {  
          return "";  
        } else {  
          long pos = len - 1;  
          while (pos > 0) {  
            pos--;  
            raf.seek(pos);  
            if (raf.readByte() == '\n') {  
              break;  
            }  
          }  
          if (pos == 0) {  
            raf.seek(0);  
          }  
          byte[] bytes = new byte[(int) (len - pos)];  
          raf.read(bytes);  
          if (charset == null) {  
            return new String(bytes);  
          } else {  
            return new String(bytes, charset);  
          }  
        }  
      } catch (FileNotFoundException e) {  
      } finally {  
        if (raf != null) {  
          try {  
            raf.close();  
          } catch (Exception e2) {  
          }  
        }  
      }  
      return null;