public static int getCompiledJavaVersionFromJavaClassFile ( InputStream classByteStream , boolean majorVersionRequested ) throws Exception { DataInputStream dataInputStream = new DataInputStream ( classByteStream ) ; // Skip the "magic number". dataInputStream . readInt ( ) ; int minorVersion = dataInputStream . readUnsignedShort ( ) ; int majorVersion = dataInputStream . readUnsignedShort ( ) ; return ( majorVersionRequested ) ? majorVersion : minorVersion ; }
getCompiledJavaVersionFromJavaClassFile Given an input stream to a Java class file this will return the major or minor version of Java that was used to compile the file . In a Maven POM file this is known as the target version of Java that was used to compile the file .