本文整理汇总了Java中java.net.JarURLConnection.getJarEntry方法的典型用法代码示例。如果您正苦于以下问题:Java JarURLConnection.getJarEntry方法的具体用法?Java JarURLConnection.getJarEntry怎么用?Java JarURLConnection.getJarEntry使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.net.JarURLConnection
的用法示例。
在下文中一共展示了JarURLConnection.getJarEntry方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import java.net.JarURLConnection; //导入方法依赖的package包/类
public void run(String[] args) throws Exception {
File tmp = createTempDir();
try {
File dir = new File(tmp, "dir!name");
dir.mkdir();
File testFile = copyResource(dir, "jar1.jar");
// Case 1: direct access
URL url = new URL("jar:" + testFile.toURI().toURL() + "!/res1.txt");
JarURLConnection conn = (JarURLConnection) url.openConnection();
JarFile file = conn.getJarFile();
JarEntry entry = conn.getJarEntry();
byte[] buffer = readFully(file.getInputStream(entry));
String str = new String(buffer);
if (!str.equals("This is jar 1\n")) {
throw (new Exception("resource content invalid"));
}
// Case 2: indirect access
URL[] urls = new URL[1];
urls[0] = new URL("jar:" + testFile.toURI().toURL() + "!/");
URLClassLoader loader = new URLClassLoader(urls);
loader.loadClass("jar1.GetResource").newInstance();
} finally {
deleteRecursively(tmp);
}
}