• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Uploading a ZIP file question

 
A Harry
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have managed to upload a ZIP file using Struts 1.1 to my server & can save it to disk there quite easily like so -

public ActionForward execute(ActionMapping mapping, ActionForm form,.......
{
DynaActionForm frm = (DynaActionForm) form;
FormFile uploadFile = (FormFile)frm.get("uploadfile");
byte[] fileData = uploadFile.getFileData();
FileOutputStream os = new FileOutputStream("test.zip");
os.write(fileData);
os.flush();
os.close();
....

the test.zip file contains a text.txt file

What I want to do is open the ZIP file in memory & process the contents of test.txt WITHOUT having to save it to disk!

Is this possible? if so any help would be greatly appreciated!

Thanks

harry
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's possible. Just use the classes in the java.util.zip package. You can use the FormFile's getInputStream() method to get an input stream for the file and use it to create in instance of java.util.zip.ZipInputStream.

Here's an article that gives you some examples:

http://www.devshed.com/c/a/Java/Zip-Meets-Java/
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic