今天在csdn上看到一个程序。
意思是说:看某个目录下面有没有"java.exe"文件,如果有,那么返回该文件的地址。其中有这么一段
 for(File file:files){
       find(file);
   }但是eclipse提示,只有jre5.0以上才能使用。在eclipse中,使用jre的版本是不是 在 “java Compiler”-> "JDK Compliance" -> Compiler complicnce level 那边设置的?还有,我使用上述代码,除了异常;
java.lang.UnsupportedClassVersionError: org/luyang/FilePathRead (Unsupported major.minor version 49.0)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
Exception in thread "main" 请问
Unsupported major.minor version 49.0 中的 version 49.0 是什么东西的版本?

解决方案 »

  1.   

    你的JDK的版本不行,支持不了foreach这样的语法.
      

  2.   

    是不是jdk 1.5 == jre5.0?????
      

  3.   

    版本低,就改成了下面的方法,就ok了。
    package org.luyang;import java.io.File;public class FilePathRead {
        public static void main(String[] args){
            FilePathRead t = new FilePathRead();
            t.find(new File("C:\\j2sdk1.4.2_10"));
        }
        
        public void find(File f){
            if(f.isDirectory()){
                String[] fileList = f.list();
                String fatherPath = f.getAbsolutePath();
                for(int i = 0; i < fileList.length; i++){
                    String fileName = fileList[i];
                    File subfile = new File(fatherPath + "\\" + fileName);
                    find(subfile);
                }
            }else{
                if(f.getName().equals("java.exe"))
                    System.out.println(f.getAbsolutePath());
            }
        }
    }
      

  4.   

    你的jre不是1.5的,eclipse把程序编译成为1.5,但你运行不了,要设置jre为1.5