Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2007

Tip: Looking for answers? Try searching our database.

ZIPPING IN JAVA WITHOUT PATH STORE

Thread view: 
valerie.en.davy@gmail.com - 13 Aug 2007 13:39 GMT
Hello,

I've searched the API's but didn't see anything about the following
problem : I'm using java.util.zip to create a zip file containig some
xmls. No trouble creating the zip but when opening it, I see the files
all have the folder structure of the location(where the xmls were)
and  where I made the zip file. To avoid this in winrar I normaly
chose in options the "do not store path" option. Can I do this in
java?

TIA, D

    private void zip (){

    File[] xmls = getFileArray(BASE_PREFIX, XML_EXTENTION);

       byte[] buf = new byte[1024];

       try {

           String outFilename = OUTPUTZIP;
           ZipOutputStream out = new ZipOutputStream(new
FileOutputStream(BASEDIR + SLASH + nbrTreated + outFilename));

           for (int i=0; i<xmls.length; i++) {

               String filename = BASEDIR + SLASH + xmls[i].getName();

               FileInputStream in = new FileInputStream(filename);

               out.putNextEntry(new ZipEntry(filename));

               int len;
               while ((len = in.read(buf)) > 0) {
                   out.write(buf, 0, len);
               }
               out.closeEntry();
               in.close();
           }

           out.close();
       } catch (IOException e) {
           e.printStackTrace();
       }
    }
valerie.en.davy@gmail.com - 13 Aug 2007 14:21 GMT
Never mind guys,

my mistake : in the ZipEntry I also used the full path filename
instead of only the name it self. Works fine now..

                   FileInputStream in = new FileInputStream(BASEDIR +
SLASH + xmls[i].getName());
                   out.putNextEntry(new
ZipEntry(xmls[i].getName()));


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.