0

I want to load a jar file dynamically however before it is loaded I'd like to read a properties file in its root. Is there a way to read the properties file from within the jar with out loading the jar?

I tried this but then realized this is something I do after the jar is loaded.

    InputStream inputStream = this.getClass().getClassLoader()
            .getResourceAsStream("jdscfg.properties");

Do I need to look into treating the file as a zip and extracting the file?

4

1 に答える 1

0

さてここに私の解決策がありました

public static InputStream getInputStreamFromZip(File f, String fileEntry) {
    try {
        ZipFile zf = new ZipFile(f);
        Enumeration entries = zf.entries();
        while (entries.hasMoreElements()) {
            ZipEntry ze = (ZipEntry) entries.nextElement();
            System.out.println("Read " + ze.getName() + "?");
            if (ze.getName().equalsIgnoreCase(fileEntry)) {
                return zf.getInputStream(ze);
            }
        }
    } catch (IOException e) {
        System.err.println("io error accessing zip file");
    }
    return null;
}
于 2013-02-27T20:20:45.937 に答える