JarFile解析jar包中application.properties

/**
* 遍历jar包所有的文件
*/
public void getAllFilesName(){
String path = “d:/hb.jar”;
try {
File file = new File(path);
JarFile jarFile = new JarFile(file);
Enumeration jarEntries = jarFile.entries();
while(jarEntries.hasMoreElements()){
JarEntry entry = jarEntries.nextElement();
System.out.println(entry.getName());
}
} catch (IOException e) {
e.printStackTrace();
}
}

/**
* 读取jar包中的某个文件
*/
@Test
public void readFileInJar(){
String path = “d:/hb.jar”;
try {
File file = new File(path);
JarFile jarFile = new JarFile(file);
//指定文件路径的位置
// ZipEntry zipEntry = jarFile.getEntry(“AppProperty.xml”);
ZipEntry zipEntry = jarFile.getEntry(“META-INF/MANIFEST.MF”);
InputStream is = jarFile.getInputStream(zipEntry);
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String temp = null;
while((temp = br.readLine())!=null){
System.out.println(temp);
}
} catch (IOException e) {
e.printStackTrace();
}
}

你可能感兴趣的:(JarFile解析jar包中application.properties)