从jar中读取文件的路径可能是这样:
file:/D:/tests.jar!/config.properties
要读取文件需要使用到JarFile. 这里做个备忘.
这个代码在windows平台下没有问题, 但是在linux下会出现异常:
[quote]Caused by: java.util.zip.ZipException: error in opening zip file
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:114)[/quote]
不知道什么原因:(
file:/D:/tests.jar!/config.properties
要读取文件需要使用到JarFile. 这里做个备忘.
/**
*
* @param filePath
* @return
* @throws IOException
*/
private InputStream getInputStreamFromJar(String filePath) throws IOException {
int pos = filePath.lastIndexOf("/");
String name = filePath.substring(pos + 1);
JarFile jarFile = new JarFile(filePath.substring(6, pos - 1));
JarEntry entry = jarFile.getJarEntry(name);
return jarFile.getInputStream(entry);
}
这个代码在windows平台下没有问题, 但是在linux下会出现异常:
[quote]Caused by: java.util.zip.ZipException: error in opening zip file
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:114)[/quote]
不知道什么原因:(