Created
April 26, 2013 17:17
-
-
Save stalep/5468815 to your computer and use it in GitHub Desktop.
reading a file thats located in a inner jar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.jar.*; | |
import java.util.zip.*; | |
import java.io.*; | |
import java.util.*; | |
public class JarReader { | |
public static void main(String args[]) { | |
try { | |
String jarName = "specj.ear"; | |
FileInputStream fin = new FileInputStream(jarName); | |
JarInputStream jin = new JarInputStream(fin); | |
ZipEntry ze = null; | |
while ((ze = jin.getNextEntry()) != null) { | |
if (ze.getName().endsWith("insurance.war")) { | |
JarInputStream jin2 = new JarInputStream(jin); | |
ZipEntry ze2 = null; | |
while ((ze2 = jin2.getNextEntry()) != null) { | |
if(ze2.getName().endsWith("persistence.xml")) { | |
// this is bit of a hack to avoid stream closing, | |
FilterInputStream in = new FilterInputStream(jin2) { | |
public void close() throws IOException { } | |
}; | |
BufferedReader rdr = new BufferedReader(new InputStreamReader(in)); | |
StringBuilder sb = new StringBuilder(); | |
for (int c = 0; (c = rdr.read()) != -1;) { | |
sb.append((char) c); | |
} | |
System.out.println(sb.toString()); | |
} | |
} | |
} | |
} | |
} | |
catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment