e138. getting a jar file using a url.txt

来自「这里面包含了一百多个JAVA源文件」· 文本 代码 · 共 31 行

TXT
31
字号
try {
        // Create a URL that refers to a jar file on the net
        URL url = new URL("jar:http://hostname/my.jar!/");
    
        // Create a URL that refers to a jar file in the file system
        url = new URL("jar:file:/c:/almanac/my.jar!/");
    
        // Get the jar file
        JarURLConnection conn = (JarURLConnection)url.openConnection();
        JarFile jarfile = conn.getJarFile();
    
        // When no entry is specified on the URL, the entry name is null
        String entryName = conn.getEntryName();  // null
    
    
        // Create a URL that refers to an entry in the jar file
        url = new URL("jar:file:/c:/almanac/my.jar!/com/mycompany/MyClass.class");
    
        // Get the jar file
        conn = (JarURLConnection)url.openConnection();
        jarfile = conn.getJarFile();
    
        // Get the entry name; it should be the same as specified on URL
        entryName = conn.getEntryName();
    
        // Get the jar entry
        JarEntry jarEntry = conn.getJarEntry();
    } catch (MalformedURLException e) {
    } catch (IOException e) {
    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?