在下有一小题,运行出错,请帮忙。谢谢阿!
  import java.io.*;
import java.util.*;
  class Tail
  {
   public static void main(String args[]) throws IOException
  
     {
      if (args[].length==0)
        System.out.println("File not exit!");
      else 
        for (int i=0;i<args.length;i++)
          { 
           File f;
           f=new File(args[i]);
           BufferedReader in=new BufferedReader (new FileReader(f));
           Array List al=new Array List ();
           while (true)
             {
              al.add(in.readLine());
              if (f.available()==0)
                {String str1[]=new String [al.length()];
                 str1=al.toArray(str1);
                  for (int i=str.length-10;i<str1.length;i++ )
                     {System.out,println(str1[i]);}
                   break;
                  }
                   
              }
          
           }
      }
   }
//编写一程序,打印命令行指定的文件的最后10

解决方案 »

  1.   

    import java.io.*;
    import java.util.*;
    public class Tail
    {
    public static void main(String args[]) throws IOException
    {
    if( args.length == 0 )
    {
    System.out.println("File not exit!") ;
    }
    else 
    {
    for ( int i=0; i<args.length; i++ )
    {
    File f;
    f=new File(args[i]);

    ArrayList al=new ArrayList ();
    BufferedReader in=new BufferedReader (new FileReader(f));

    while (true)
    {
    String s = in.readLine() ;

       if( s == null )
       {
       break ;
       }
       al.add( s ) ;
    }

          Object str1[] = al.toArray() ;

           for ( int j=str1.length-10; j<str1.length; j++ )
           {
            System.out.println ( (String)str1[j] ) ;
           }
    }
    }
    }
    }
    输出文件的最后十行
      

  2.   

    Thank you very very much!