本文整理汇总了Java中java.net.URLClassLoader.findResource方法的典型用法代码示例。如果您正苦于以下问题:Java URLClassLoader.findResource方法的具体用法?Java URLClassLoader.findResource怎么用?Java URLClassLoader.findResource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.net.URLClassLoader
的用法示例。
在下文中一共展示了URLClassLoader.findResource方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import java.net.URLClassLoader; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Path jarPath = Paths.get(System.getProperty("user.dir", "."), "test.jar");
try {
createJar(jarPath);
URL j = new URL("jar:file:" + jarPath.toString() + "!/");
URLClassLoader ucl = new URLClassLoader(new URL[]{j});
ucl.findResource("resource.txt");
URL r = new URL("jar:file:" + jarPath.toString() + "!/resource.txt");
if (!Handler.URLS.contains(r))
throw new AssertionError("jar: URL handler not invoked");
}
finally {
Files.delete(jarPath);
}
}
示例2: setUpFileObjects
import java.net.URLClassLoader; //导入方法依赖的package包/类
/** Set up given number of FileObjects */
protected FileObject[] setUpFileObjects(int foCount) throws Exception {
tmp = createTempFolder();
destFolder = LocalFSTest.createFiles(foCount, 0, tmp);
File xmlbase = generateXMLFile(destFolder, new ResourceComposer(LocalFSTest.RES_NAME, LocalFSTest.RES_EXT, foCount, 0));
File jar = Utilities.createJar(tmp, "jarxmlfs.jar");
cloader = new URLClassLoader(new URL[] { jar.toURL() });
URL res = cloader.findResource(PACKAGE + xmlbase.getName());
xmlfs = new XMLFileSystem();
xmlfs.setXmlUrl(res, false);
FileObject pkg = xmlfs.findResource(PACKAGE);
return pkg.getChildren();
}