日期:2014-05-20  浏览次数:20749 次

一个小程序,有点问题!大虾来指点下!!
import   java.util.*;
import   java.io.*;
public   class   E04_UpperCase   {
    //   Report   all   exceptions   to   console:
    public   static   void   main(String   args[])
    throws   Exception   {
        LinkedList   lines   =   new   LinkedList();
        BufferedReader   in   =
            new   BufferedReader(
                new   FileReader(args[0]));
        String   s;
        while((s   =   in.readLine())!=   null)
            lines.add(s);
        in.close();
        Iterator   it   =   lines.iterator();
        while(it.hasNext())
            System.out.println(
                ((String)it.next()).toUpperCase());
      }
}   ///:~
这是 <JAVA编程思想> > 里的一道题答案,可以编译成功,但是执行的时候就会出现java.lang.ArrayIndexOutOfBoundsException,我弄不明白,链表那个地方出界???

------解决方案--------------------
new FileReader(args[0]));
---------------------------
个人感觉是这句话
args[0]表示这个程序的运行需要参数,该参数是一个文件名。
因此,你在运行这个类的时候,一定要带上一个参数,比如:
java E04_UpperCase.class test.txt