try:
change
   for(int i = strs.size();i>0;i--)
to
   for(int i = strs.size()-1;i>=0;i--)我没有运行,希望成功.

解决方案 »

  1.   

    for(int i = strs.size()-1;i>0;i--){
      

  2.   

    package c10;
    import java.io.*;
    import java.util.*;
    public class PrintText{
         public static void main(String[] args){
                 Vector strs = new Vector();
                 try{
                   //这样更好,因为DataInputStream的readLine()方法已不推荐使用
                     BufferedReader in =
                         new BufferedReader(
                           new InputStreamReader(
                             //这里输入实际的文件路径
                             new FileInputStream("e:\\TProject\\techpms\\work\\src\\com\\comtop\\app\\usermanagement\\c10\\input.txt")));
                  /*
                   DataInputStream in =
                       new DataInputStream(
                         new BufferedInputStream(
                         //这里输入实际的文件路径
                           new FileInputStream("e:\\TProject\\techpms\\work\\src\\com\\comtop\\app\\usermanagement\\c10\\input.txt")));
                    */
                     String s,s2 = new String();
                     while((s= in.readLine()) != null){
                             s2 = s+"\n";
                             strs.addElement(s2);
                     }
                     in.close();
                     for(int i = strs.size();i>0;i--){
                       //这里如果用for(int i = strs.size()-1;i>0;i--){
                       //输出时input.txt文件中的第一行将不会输出
                       //所以将String temp = (String)strs.elementAt(i);
                       //改为String temp = (String)strs.elementAt(i-1);
                   String temp = (String)strs.elementAt(i-1);
                   System.out.print(i+"   "+temp);
                     }             }catch(Exception e){
                   e.printStackTrace();
            }
         }
    }