試著尋找最後一個"\r\n"或0d0a(非文件尾部),下一個位置就是文件的最後一行了

解决方案 »

  1.   

    RandomAccessFile asdf=new  RandomAccessFile("d:\\test.zip","rw");
        byte b[]=new byte[10];
        long ll_length,index=1;
        ll_length=asdf.length()-10;
    asdf.seek(ll_length-1000);
    RandomAccessFile可以把定位文件的任何位置,
      

  2.   

    to signboy(横):
    你怎么知道最后一行的byte数.
      

  3.   

    BufferedReader in = new BufferedReader(new FileReader(file));
    String s;
    s = in.readLine();
    Vector fileBuffer = new Vector();
    while( null != s)
    {
        fileBuffer.addElement(s);
        s = in.readLine();
    }
    这样,通过fileBuffer的size()可以找到该文件一共有多少行,不管你是想直接在这个文件上进行操作,或者是把最后一行去掉然后生成一个新文件都可以,这种东西只要自己用不同的方法试试不就可以了吗?
      

  4.   

    还是用RandomAccessFile 打开文件,然后从后往前查找行结束符,取出结束符之后的就行了.(如果最后两个字节为行结束符,就找前面一个了)
      

  5.   

    如果是个文本文件的话 要定位的话
    我到是有一个笨办法 当然还是要读完整个文件
    //准备
    File fd=new File(filepath);
    RandomAccessFile raf=new RandomAccessFile(fd,"rw");
    String temp=new String();
    int point=0;
    //准备工作做完以后,要用到RandomAccessFile类中的三个方法(或者4个)
    //readLine()  seek()  length()  getfilepointer()
    while(raf.getfilepointer()<raf.length())
    {
         point=raf.getfilepointer();      //这里就是获得了当前随
                                          //机读取文件的指针
         temp=raf.readLine();            //读一行,同时指针下移一行
     }
         raf.seek(point);                 //这个时候指针已经指向了最后一行
                                          //用seek定位就可以了
         然后就可以任意进行你想要对这一行的读写操作了
        
      

  6.   

    java.io.RandomAccessFile in=new java.io.RandomAccessFile("c:\\kkk.txt","r");
        String str=null;
        int row=0; 
        while( (str=in.readLine())!=null ){
           row++;
         }
        while (row-- >= 0 ) {in.readLine();}
        //the file pointer pointes to the last line.