This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes Programatically creating directory in zip file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Programatically creating directory in zip file" Watch "Programatically creating directory in zip file" New topic
Author

Programatically creating directory in zip file

Logeswaran Radhakrishnan
Greenhorn

Joined: Apr 20, 2010
Posts: 13
Hi

I have a two strings A and B and a document ,i want to create a folder Structure A->B->document in the ZIP file programatically.
Help me out how to create a folder in the zip file with the given string .



Thanks and Regards
Logeswaran
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

Just add the directory in the name in the ZipEntry: directory/file.txt


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Logeswaran Radhakrishnan
Greenhorn

Joined: Apr 20, 2010
Posts: 13
Hi Rob

Thanks for the immdiate reply.But that doesnt help me out.
Let me brief my scenario.

Consider that my file resides in C:\\file.doc.I ll fetch that file name programatically by using file.list().

After this the user will give two strings as input .Only Strings not the directories .

I have to make two directories in the zip file for the given two strings inside which i have to add my file( C:\\file.doc) .




Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

Search in this forum for my posts regarding zipping. I've posted (pseudo)code for recursively zipping entire directories before.
Logeswaran Radhakrishnan
Greenhorn

Joined: Apr 20, 2010
Posts: 13
Hi Rob,
I have gone through your postings.Using it what i have done is i have created a directory structure for the given strings by
.


Inside the dir2 folder i have copied some files.When i tried to zip the dir2 it shows the following error.



I think i have to set the folder access permissions programatically.Is that right?

Help me out to solve the issue.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

You shouldn't mix \\ and / inside file names.
Logeswaran Radhakrishnan
Greenhorn

Joined: Apr 20, 2010
Posts: 13
Thanks Rob the issue is resolved..
 
jQuery in Action, 2nd edition
 
subject: Programatically creating directory in zip file
 
Similar Threads
Creating zip containg both files and folders
Zip a folder programatically ??
Creating .ear file from zip file
Ruthlessly smash the bug...but where is it?
Adding files to jar