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.
The VectorSync_1.0.0.201403121100.jar have a structure like :
VectorSync:
The .classpath of the project where i imported the .Jar File is:
<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:
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
.
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 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)));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.