本文整理匯總了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);
}
}