简体   繁体   中英

how to read a file from a Jar file located on remote server

I want to read and copy file from jar file(for eg. application.xml from EAR )located on remote server to local machine. when i search on net for this, i found java.util.jar.JarFile API. This API read jar only from local machine as it takes only string as input and not URL for jar location in constructor. I know org.apache.commons.net.ftp.FTPClient API.This API can copy any file or even jar from remote server to local machine. But my requirement is to copy only single file from jar located on remote server.

Please help me in this regard .

Thanks Sameer

I think you might have a better luck if you try creating your own downloading mechanism, something along these lines:

    ZipInputStream zip = null;
    try {
        zip = new ZipInputStream(url.openStream());

        ZipEntry entry;
        do{
            entry = zip.getNextEntry();
        } while(!yourExpectedFileName.equals(entry.getName())


        while(zip.available()){
             //read your data
        }
        zip.closeEntry();

    } finally {
        if (zip != null)
            zip.close();
    }

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM