The NoteBook of EricKong

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  611 Posts :: 1 Stories :: 190 Comments :: 0 Trackbacks
import java.io.*; 
public class ClassVersionChecker { 
public static void main(String[] args) throws IOException { 
   
for (int i = 0; i < args.length; i++) 
        checkClassVersion
(args[i]); 
} 
 
   
private static void checkClassVersion(String filename) 
       
throws IOException 
   
{ 
       
DataInputStream in = new DataInputStream 
         
(new FileInputStream(filename)); 
 
       
int magic = in.readInt(); 
       
if(magic != 0xcafebabe) { 
         
System.out.println(filename + " is not a valid class!");; 
       
} 
       
int minor = in.readUnsignedShort(); 
       
int major = in.readUnsignedShort(); 
       
System.out.println(filename + ": " + major + " . " + minor); 
       
in.close(); 
   
} 
} 

The possible values are :

major  minor Java platform version  
45       3           1.0 
45       3           1.1 
46       0           1.2 
47       0           1.3 
48       0           1.4 
49       0           1.5 
50       0           1.6 
posted on 2010-12-10 17:42 Eric_jiang 阅读(254) 评论(3)  编辑  收藏 所属分类: Java

Feedback

# re: Java API to find out the JDK version a class file is compiled for 2010-12-23 13:24 Eric_jiang
http://www.webspherechina.net/club/thread-16869-1-1.html  回复  更多评论
  

# re: Java API to find out the JDK version a class file is compiled for 2010-12-23 13:26 Eric_jiang
http://www.webspherechina.net/club/thread-7698-1-1.html  回复  更多评论
  

# re: Java API to find out the JDK version a class file is compiled for 2010-12-23 13:26 Eric_jiang
http://www.webspherechina.net/club/thread-14072-1-1.html  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: