Я пытаюсь создать сервлет, который может распаковать папку, содержащую 3 файла csv, а затем распечатать данные каждого файла csv.
Я пытался использовать ZipInputStream, но он не дает мне возможности читать/печатать содержимое каждого csv.
Поскольку я создаю это веб-приложение на GAE, я не могу использовать FileOutputStream.
Существуют ли способы использовать ZipInputStream для распаковки и чтения отдельных CSV-файлов без необходимости создания CSV-файла в GAE?
открытый класс AdminBootStrap расширяет HttpServlet {
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
resp.setContentType("text/plain");
PrintWriter out = resp.getWriter();
try {
ServletFileUpload upload = new ServletFileUpload();
resp.setContentType("text/plain");
FileItemIterator iterator = upload.getItemIterator(req);
while (iterator.hasNext()) {
FileItemStream item = iterator.next();
InputStream in = item.openStream();
if (item.isFormField()) {
out.println("Got a form field: " + item.getFieldName());
} else {
out.println("Got an uploaded file: " + item.getFieldName() +
", name = " + item.getName());
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(in));
ZipEntry entry;
// Read each entry from the ZipInputStream until no
// more entry found indicated by a null return value
// of the getNextEntry() method.
//
while ((entry = zis.getNextEntry()) != null) {
out.println("Unzipping: " + entry.getName());
//until this point, i'm only available to print each csv name.
//What I want to do is to print out the data inside each csv file.
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
// throw new ServletException(ex);
}
}
}