用LineInputStream
先取得函数,然后.....

解决方案 »

  1.   

    函数???是不是行数啊~~JAVA 的API好多啊~~!!
      

  2.   

    LineInputStream 也没有返回总行数的方法啊。
      

  3.   

    line.txt
    =====================
    1111111111111111111111111
    222222222222222222222222222
    333333333333333333333333333
    4444444444444444444444444444
    5555555555555555555555555555
    66666666666666666666666666666
    7777777777777777777777777777777
    88888888888888888888888888
    9999999999999999999999999
    0000000000000000000000
    1111111111111111112222222222
    2222222222222222223333333333
    3333333333333333334444444444
    4444444444444444445555555555555
    55555555555555555566666666666666LineRead.java
    =====================
    import java.io.*;public class LineRead {    public static void main(String args[]) {
        
         try {
        
         FileInputStream fis = new FileInputStream("c:/line.txt");
         DataInputStream in_data = new DataInputStream(fis);
         LineNumberInputStream lnis = new LineNumberInputStream(fis);
        
         int i=0;
         String s;
    while(( s=in_data.readLine()) != null) {
    i++;
    }
    System.out.print(i);

    lnis.setLineNumber(11);
    System.out.print(lnis.getLineNumber());

    int k=0;
    while(( k=lnis.read()) != -1) {
    System.out.print(k);
    }
    }catch( IOException e ) {
    System.out.println(e.toString());
    }
    }
    }怎么没有输出结果??
      

  4.   

    LineInputStream这个API我看了,JAVA不推荐使用,有没有其他的方法了?谢谢上面那位兄台的建议
      

  5.   

    不让用LineInputStream,那怎么办啊?那只有做一个FileInputStream,然后遍历文件,每一行做为一个对象压入Stack,然后弹出十行,好象代价也不小啊。