Last active
August 29, 2015 14:28
-
-
Save ecelis/93080a9ba282d2bf3784 to your computer and use it in GitHub Desktop.
Java Version Checker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
/* Code taken from http://www.rgagnon.com/javadetails/java-0544.html | |
Usage | |
> java ClassVersionChecker ClassVersionChecker.class | |
ClassVersionChecker.class: 49 . 0 | |
*/ | |
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(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment