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,我弄不明白,链表那个地方出界???

解决方案 »

  1.   

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

  2.   

    我刚才试了下,只是能把test.txt这几个字大写,但是不能读出它的内容!我还不知道该怎么添加命令行参数!!大虾再指点下!!
      

  3.   

    java a class file,you can add a parameter following de class name ;
    if you use the parameter in you program,you must add the param
    one floor is right
      

  4.   

    do you use command?or ide?
      

  5.   

    test.txt
    这应该是一个实实在在的文件啊,你的程序路径下有这个文件吗?
      

  6.   

    我用的CMD.现在解决了,IDE?我下了个NETBEANS,那叫个不懂,现在就看了看,哎,那有好的教材和好的学习方法1!