[英]Read files from a folder inside a jar file on classpath
I have a project with a graphical editor (like GMF technology) and I need read a file placed on a .Jar library that is on the classpath of the project. 我有一个带有图形编辑器的项目(例如GMF技术),我需要读取放置在项目类路径上的.Jar库中的文件。
The VectorSync_1.0.0.201403121100.jar have a structure like : VectorSync_1.0.0.201403121100.jar的结构类似于:
VectorSync: VectorSync:
The .classpath of the project where i imported the .Jar File is: 我导入.Jar文件的项目的.classpath是:
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="/home/jperezmedina/git/arom/arom-core/target/scala-2.9.0/aromslave_2.9.0-0.1.jar"/>
<classpathentry kind="lib" path="/home/jperezmedina/runtime-EclipseApplication/DefaultProject.arom/lib/VectorSync_1.0.0.201403121100.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
I used this method to try acces a .xml file: 我使用此方法尝试访问.xml文件:
JarFile file = new JarFile("VectorSync_1.0.0.201403121100.jar");
BufferedReader input1 =
new BufferedReader(new InputStreamReader(file.getClass().
getClassLoader().getResourceAsStream("model/VectorSync.xml")));
But the method used return all times null
. 但是使用的方法始终返回
null
。
Could you help me to solve this problem? 您能帮我解决这个问题吗?
Thanks 谢谢
您尝试过这种方法吗?
Thread.currentThread().getContextClassLoader().getResourceAsStream(filename);
If you look into the JarFile
you will notice that it offers you the api to do so 如果查看
JarFile
您会发现它为您提供了执行此操作的api
JarFile file = new JarFile("VectorSync_1.0.0.201403121100.jar");
ZipEntry entry = file.getEntry("model/VectorSync.xml");
BufferedReader input1 = new BufferedReader(
new InputStreamReader(file.getInputStream(entry)));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.