开发者

How to detect a JAR file?

How could I know if a inputstream is a JAR file?

I can detect a JAR file by using:

try {
  JarFile jar = new JarFile("file");
} catch(ZipException开发者_如何学Python e) {
  // not a jar file
  ...
}

But how should I do if I only have the inputstream? Do I need to write it to a file?

Any elegant way?


http://download.oracle.com/javase/1.4.2/docs/api/java/util/jar/JarInputStream.html#JarInputStream(java.io.InputStream)

try {
  JarInputStream jar = new JarInputStream(inputStream);
} catch(Exception e) {
  // not a jar file
  ...
}


If you want to do some intelligent prefiltering, you can look for the local file header signature byte: 0x04034b50

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜