只能用反射了,你看看API.
不过你看看可不可以把那些组织成一个数组什么的。

解决方案 »

  1.   

    用数组
    String file[] = new String[5];
     file[0] = new String("1111");
     file[1] =new String("2222");
    file[1] =new String("3333");
    file[1] =new String("4444");
    file[1] =new String("5555");
    for(int i= 0;i<file.length;i++)
    {
    System.out.println(file[i]);
    }
      }
      

  2.   

    String Item[] = new String[5];
     Item[0] = new String("1111");
     Item[1] =new String("2222");
    Item[2] =new String("3333");
    Item[3] =new String("4444");
    Item[4] =new String("5555");
    for(int i= 0;i<Item.length;i++)
    {
    System.out.println(Item[i]);
    }
      }
      

  3.   

    public class TestMethod
    {
        public TestMethod()
        {
        }
        
        public void print1()
        {
            System.out.println("aaa");
        }
        
        
        
        public static void main(String[] args) throws Exception
        {
            TestMethod test = new TestMethod();
            
            Method method = null;
            
            int i =1;
            method = test.getClass().getMethod("print" + i, null);
            
            method.invoke(test,null);
        }
    }
      

  4.   

    public class FieldSet {
        private String file0 = "1";
        private String file1 = "2";
        private String file2 = "3";
        private String file3 = "4";
        private String file4 = "5"; 
        
        public void printFieldByFor(){
            Field[] fields = this.getClass().getDeclaredFields();
            for (int i = 0; i < fields.length; i++) {
                try {
                    System.out.println(fields[i].get(this).toString());
                } catch(Exception e) {
                    e.printStackTrace();
                }
            }
        }
        
        public static void main(String[] args) {
            FieldSet set = new FieldSet();
            set.printFieldByFor();
        }
    }
      

  5.   

    public class FieldSet {
        private String file0 = "1";
        private String file1 = "2";
        private String file2 = "3";
        private String file3 = "4";
        private String file4 = "5"; 
        
        public void printFieldByFor(){
            Field[] fields = this.getClass().getDeclaredFields();
            for (int i = 0; i < fields.length; i++) {
                try {
                    System.out.println(fields[i].get(this).toString());
                } catch(Exception e) {
                    e.printStackTrace();
                }
            }
        }
        
        public static void main(String[] args) {
            FieldSet set = new FieldSet();
            set.printFieldByFor();
        }
    }