I’m having problems setting the path of the zip file, X, in ZipFile zipfile = new ZipFile("X");.
I don’t want to hardcode the path such that it becomes ZipFile zipfile = new ZipFile("C:/docs/data.zip");.
I want to do something like :
ZipFile zipfile = new ZipFile(getServletContext().getResourceAsStream("/WEB-INF/" + request.getAttribute("myFile").toString());
Where the path of the zip file is determined by the selection of the user. But, this gives an error, because this only works for InputStream.
Previously, I’ve already retrieved the multipart/form data and gotten the real path of the zip file:
String path = getServletContext().getRealPath("/WEB-INF");
UploadBean bean = new UploadBean();
bean.setFolderstore(path);
MultipartFormDataRequest multiPartRequest = new MultipartFormDataRequest(request);
bean.store(multiPartRequest); //store in WEB-INF
// get real path / name of zip file which is store in the WEB-INF
Hashtable files = multiPartRequest.getFiles();
UploadFile upFile = (UploadFile) files.get("file");
if (upFile != null) request.setAttribute("myFile", upFile.getFileName());
Any solutions to this?
I don’t understand why you don’t use the real path that you already have.
Anyway, you can work with a
ZipInputStream.This way you can handle your file as a simple Stream. The only big differences are the
getName()method andsize()that you can’t directly access. With a ZIS you will be able to read every entry.Resources :