Java网络教程:JarURLConnection

原文链接

Java的JarURLConnection类用来连接Java Jar文件。一旦连接上,你可以获取Jar文件的信息。一个简单的例子如下:

[code lang=”java”]
String urlString = "http://butterfly.jenkov.com/"
+ "container/download/"
+ "jenkov-butterfly-container-2.9.9-beta.jar";

URL jarUrl = new URL(urlString);
JarURLConnection connection = new JarURLConnection(jarUrl);

Manifest manifest = connection.getManifest();

JarFile jarFile = connection.getJarFile();
//do something with Jar file…
[/code]

原创文章,转载请注明: 转载自并发编程网 – ifeve.com本文链接地址: Java网络教程:JarURLConnection

  • Trackback 关闭
  • 评论 (1)
    • msi1993
    • 2017/04/21 5:09下午

    JarURLConnection是抽象类 无法实例化

    Users should cast the generic URLConnection to a JarURLConnection when they know that the URL they created is a JAR URL, and they need JAR-specific functionality. For example:

    URL url = new URL(“jar:file:/home/duke/duke.jar!/”);
    JarURLConnection jarConnection = (JarURLConnection)url.openConnection();
    Manifest manifest = jarConnection.getManifest();

    http://docs.oracle.com/javase/8/docs/api/java/net/JarURLConnection.html

return top