1. Read a file in the jar package
InputStream input = getClass().getResourceAsStream ("file relative path");//Read the input stream of the file
String allPath = getClass().getResource(""); //Read the full path, such as jar: file:/c:/xxx.jar!/org/apache/...
2. Read all files in a directory in the jar package
JarFile needs to be used, for example:
File file = new File("full path to jarFile");
String path="META-INF";
JarFile jar = new JarFile(file);
Enumeration<JarEntry> entries = jar.entries();
while(entries.hasMoreElements())
{
JarEntry tmp = entries.nextElement();
final String name = entries.nextElement().getName();
if (name.startsWith(path + "/")) { //匹配path路径
System.out.println(name);
}
}