对于JAR文件中的资源,类似以下内容:
URL url = MyClass.class.getResource("MyClass.class");String scheme = url.getProtocol();if (!"jar".equals(scheme)) throw new IllegalArgumentException("Unsupported scheme: " + scheme);JarURLConnection con = (JarURLConnection) url.openConnection();JarFile archive = con.getJarFile();Enumeration<JarEntry> entries = archive.entries();while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); if (entry.getName().startsWith("com/y/app/")) { ... }}您可以使用文件系统或许多其他存储库中“爆炸”的资源来执行相同的操作,但这并不那么容易。您需要为每个要支持的URL方案指定特定的代码。



