Creating a zip file from the contents of a directory

hi, I am having a problem as the title suggests with a zip fil creation...
using the basic example zip.java i wished to edit it so it doesnt zip a file fro the current directory but rather a directory i inputted.
It is able to read the first file then throws out the following error with the code below it:
java.io.FileNotFoundException: test.jpg (The system cannot find the file specified)
import java.io.*;
import java.util.zip.*;
public class Zip {
   static final int BUFFER = 2048;
   public static void main (String argv[]) {
      try
         BufferedInputStream origin = null;
         FileOutputStream dest = new FileOutputStream("C:/Documents and Settings/Phil/My Documents/My Pictures/Work/test.zip");
         CheckedOutputStream checksum = new CheckedOutputStream(dest, new Adler32());
         ZipOutputStream out = new
           ZipOutputStream(new BufferedOutputStream(checksum));
         //out.setMethod(ZipOutputStream.DEFLATED);
         byte data[] = new byte[BUFFER];
         // get a list of files from current directory
         File f = new File("C:/Documents and Settings/Phil/My Documents/My Pictures/Work/");
         f.listFiles();
         String files[] = f.list();
         for (int i=0; i<files.length; i++)
            System.out.println("Adding: "+files);
FileInputStream fi = new FileInputStream(files[i]);
origin = new BufferedInputStream(fi, BUFFER);
ZipEntry entry = new ZipEntry(files[i]);
out.putNextEntry(entry);
int count;
while((count = origin.read(data, 0,
BUFFER)) != -1)
out.write(data, 0, count);
origin.close();
out.close();
catch(Exception e)
e.printStackTrace();
After investigation i am lead to believe this is because the method returns an array of file and directory names only but not their path and the unqualified names would have therefore be defaulted to the current working directory. Something i understand if this is the case.
So instead i used the File.listFiles() method to return an array
of File objects, instead of an array of Strings as shown in the snippet of the changed code below (the changed code highlighted)...but arrived at another error on the second section of highlighted code meaning i cant compile. I cant understand why this is so!
The error is: "cannot find symbol, Symbol: Contructor ZipEntry (Java.IO.file), location: class.java.util.zip.ZipEntry"
File f = new File("C:/Documents and Settings/Phil/My Documents/My Pictures/Work/");
         **************File g[] = f.listFiles();***************
         **************String files[] = f.list();**************
         for (int i=0; i<g.length; i++)
            System.out.println("Adding: "+g);
FileInputStream fi = new FileInputStream(g[i]);
origin = new BufferedInputStream(fi, BUFFER);
**************ZipEntry entry = new ZipEntry(g[i]);************
out.putNextEntry(entry);
int count;
while((count = origin.read(data, 0,
BUFFER)) != -1)
out.write(data, 0, count);
origin.close();
out.close();
Any help and thoughts most appreciated. Thank u in advance

I'll admit i took 1 look at that reply an thought "thats stupid that wont work"...
then a second look an though "actually, i should work i cant believe i didnt think of that"
Anyways i tried it and it did work
How are the duke dollars awarded, cos u should have them ordinary_guy
cheers!

Similar Messages

  • How can i create my own file from the Adobe Export PDF to Word ?

    How can I create my own file from the file of the Adobe Export PDF to Wodrd?

    If there is handwritten content in your PDF then ExportPDF can't convert that to word.
    ~Deepak

  • Compress/zip files from the command line in Windows 7?

    In Windows 7 is there a native way to compress or zip files from the command line?  I'd like to do it without installing any third-party utilities such as 7Zip.

    I fully agree that Compact is not the answer. There are additional concerns with the Compact command. It enables disk compression which is a total no-no. Very bad! It makes your computer very slow and is quite difficult to undo. The only time anyone should
    use this command is when they're removing disk compression because someone turned it on to save space.  Turning this off has to be done by booting into the recovery console, if my memory serves me correctly, and it's a real nuisance.  So
    definitely no to the Compact command.
    If you wanted to compress files before sending them to another drive, or over a network, or by email, then Compact wouldn't actually help at all because the files have to get uncompressed whenever they're accessed, especially before sending them anywhere. 
    When I say accessed, I mean that just looking at a file triggers the OS to decompress it in the background and present you with an uncompressed version of it then letting you change it and recompressing it again for storage every single time you access the
    file, which is why your machine gets slower.  If you have folders or files that have blue text instead of black, then you've probably already made this mistake.
    I would also like to know if there is a built-in command for zipping files/directories, or, if there isn't such a thing built into Windows, then I would like to know if this is feature is accessible through Visual Studio, which would be just as good as having
    a command-line program for those of us that do a bit of programming.
    If anyone knows if MS provides such a feature, either by command-line or through an API, then I'd love to hear about it.  Good luck to those of you that have disk compression turn on.

  • Anyway to create a domain file from the published site?

    My friend and I both use iWeb. She created a site and her hard drive has since crashed. I am trying to see if there is a way to make a domain file from what's on the web without going through creating a page again. Any ideas?

    Welcome to the discussions. No, there's no way to create a domain file from the published site. If she doesn't have a backup of her Domain file (e.g. via Time Machine), paragraph 2.3 of this FAQ page gives some tips on how to use published files, graphics, photos, etc., to help rebuild the site from scratch:
    http://iwebfaq.org/site/iWebBackupretrieve.html
    And it may be an opportunity to switch to another site building tool — see this post:
    _Domain file - iWeb becoming a headache_

  • Creating a zipped file from table data

    I am currently extracting data from a table and creating a flat file which is read later to create a compressed (zip) file.
    Is there a way that I can create a zipped file in one step (i.e. directly from the table data)? I am trying to reduce the number of file i/o hits in my appication.
    Thanks,
    Minesh

    Is there a way that I can create a zipped file in one step (i.e. directly from the table data)?Yes. Instead of doing something like:
    FileOutputStream fout = new FileOutputStream("flatfile");
    // write using foutdo this:
    ZipOutputStream zout = new ZipOutputStream("flatfile.zip");
    zout.putNextEntry(new ZipEntry("flatfile"));
    // write using zout

  • Creating an xml file from the Basic java Object

    how to create an XML file using the values available in the object with reference to an xsd or dtd file..
    (OR )
    is it possible to write the contents of an object to an xml file without knowing the dtd or xsd file .......

    how to create an XML file using the values available in the object with reference to an xsd or dtd file..
    (OR )
    is it possible to write the contents of an object to an xml file without knowing the dtd or xsd file .......

  • How do I create individual xml files from the parsed data output of a xml file?

    I have written a program (DOM Parser) that parses data from a XMl File. I would like to create an individual file with the corresponding name for each set of data parsed from the xml document. If the parsed output is Single, Double, Triple, I would like to create an individual xml file (Single.xml, Double.xml, Triple.xml)with those corresponding names. How do I create the xml files and give each file the name of my parsed data output? Thanks in advance for your help.
    import java.io.IOException;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.ParserConfigurationException;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    import org.xml.sax.SAXException;
    public class MyDomParser {
      public static void main(String[] args) {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      try {
      DocumentBuilder builder = factory.newDocumentBuilder();
      Document doc = builder.parse("ENtemplate.xml");
      doc.normalize();
      NodeList rootNodes = doc.getElementsByTagName("templates");
      Node rootNode = rootNodes.item(0);
      Element rootElement = (Element) rootNode;
      NodeList templateList = rootElement.getElementsByTagName("template");
      for(int i=0; i < templateList.getLength(); i++) {
      Node theTemplate = templateList.item(i);
      Element templateElement = (Element) theTemplate;
      System.out.println("Template" + ": " +templateElement.getAttribute("name")+ ".xml");
      } catch (ParserConfigurationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } catch (SAXException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();

    Ive posted the new code but now I'm getting a FileAlreadyExistException error. How do I handle this exception error correctly in my code?
    import java.io.IOException;
    import java.nio.file.FileAlreadyExistsException;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.ParserConfigurationException;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    import org.xml.sax.SAXException;
    public class MyDomParser {
      public static void main(String[] args) {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      try {
      DocumentBuilder builder = factory.newDocumentBuilder();
      Document doc = builder.parse("ENtemplate.xml");
      doc.normalize();
      NodeList rootNodes = doc.getElementsByTagName("templates");
      Node rootNode = rootNodes.item(0);
      Element rootElement = (Element) rootNode;
      NodeList templateList = rootElement.getElementsByTagName("template");
      for(int i=0; i < templateList.getLength(); i++) {
      Node theTemplate = templateList.item(i);
      Element templateElement = (Element) theTemplate;
      System.out.println(templateElement.getAttribute("name")+ ".xml");
      for(int i=0; i < templateList.getLength(); i++) {
      Node theTemplate = templateList.item(i);
      Element templateElement = (Element) theTemplate;
      String fileName = templateElement.getAttribute("name") + ".xml";
      Files.createFile(Paths.get(fileName));
      System.out.println("File" + ":" + fileName + ".xml created");
      } catch (ParserConfigurationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } catch (SAXException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();

  • Slideshow Elements 9:  Lose audio when creating a .pdf file from the slideshow

    I created the slideshow in Elements 9.  Works great.  Created the .pdf and I lose the audio. I'm trying to send the slideshow via email so it can't be too huge, so I didn't consider the .wmv.  In troubleshooting it mentioned removing the artwork as one potential issue and didn't get into detail as to the other problems could be. So  I removed the artwork in Itunes from the .mp3.  I converted from .mp3 to .wav to see if that made a difference. Neither helped.  I was able to create the .pdf of a slideshow with audio in Elements 7.  What do I do to make it work?
    Trying to get this figured out to send the slideshow for Christmas so any help/suggestions are appreciated...13 days to go

    Sorry for the late reply. Have you been able to send the file?
    However, i created a slideshow with a mp3 file and when i output the same into pdf format, it just played fine with the music i applied while creating.
    Can you mention the number and size of the files that you used to create the slideshow.
    Just to add, you can also create online albums with various templates like christmas and many more and can share them with friends.

  • How to create a xml file from the jsp page?

    I'm a beginner of the develop xml,my question like this,
    there has a jsp page,some parameters in it,I wanna get the parameters and create a xml file,so,what parser method should I use?
    And how to create a new xml file,when the file haven't exist at first?
    pls give some code,thanks.

    a ggod link for u http://www.theserverside.com/resources/article.jsp?l=JSP-XML2

  • How to download the AppIntegrator zip file from the SAP Service Market Plac

    Hi All,
    I want to download com.sap.portal.howtos.webapp.par file from SAP Market Place. KIndly guide me how to download par file from market place.
    Regards,
    Bidyut

    Below documents will help you to download app integrator
    Step-By-Step Guide to implement Application Integrator
    Integrating your Web Front-ends into the SAP Enterprise Portal using the Application Integrator

  • Is it safe to remove setup32/setup64 files from the uninstall\third party directory?

    Found 2 setupfiles in the %PROGRAM FILES%\common files\adobe\installers\uninstall\thirdparty\{GUID}\Adobe Photoshop lightroom 5 ccm directory.
    SAFE to get rid of them?  living a limited c:\ SSD boot device... so gotta be thrifty... Thanks!

    Hi Raj,
    The “Everyone” share access is a remnant of legacy Exchange functionality (pre-Exchange 5.0). 
    For Exchange 2003, we do not see any Microsoft Exchange 2003 dependencies upon those shares. 
    From the Exchange perspective, it is safe to remove the “Everyone” share permission. 
    However, there may be any 3rd party applications which still use Exchange 2003 in a legacy fashion, their ability to access proxy DLLs/addressing templates, and reading diagnostic logging pages may be hampered.
    To mitigate such a risk, I suggest we can replace “Everyone” with “Authenticated Users” in order to bypass any audit concerns, yet still allow 3rd party applications to access those shares. Additionally, here is a KB descripted the detailed functions about
    these shared folder:
    http://support.microsoft.com//kb/812290
    Regards,
    Winnie Liang
    TechNet Community Support

  • Read a zip file from Application server.

    Hi,
    Is there a way to read a zip file from the applicatoin server to internal table in ABAP program?  The operation system is running MS windows server.  The zip file contains only 1 text file.  I tried to use open dataset 'uncompress', and use read dataset, but read dataset gave me sy-subrc = 4.  Any feedback is greatly appreciated.
    Thanks.

    hi,
    to convert xstring to text you can use this:
    DATA unzipped_data TYPE xstring.
    DATA text_data TYPE string.
    DATA conv_x2c TYPE REF TO cl_abap_conv_in_ce.
    conv_x2c = cl_abap_conv_in_ce=>create( ).
    conv_x2c->convert( EXPORTING input = unzipped_data IMPORTING data = text_data ).
    moreover, if you want to split your text at "end of line" (CR LF in microsoft windows) into lines:
    DATA text_lines TYPE TABLE OF string.
    SPLIT text_data AT cl_abap_char_utilities=>cr_lf INTO TABLE text_lines.

  • Missing folder structure in zip file from Theme Editor

    Hi all gurus!
    I have an interesting problem with this background: I want to change the customer brand image in the portal header and do som other modifications. For this reason I have made a copy of one of the standard portal themes, as I'm supposed to do, and I have downloaded that zip file from the portal.
    When unzip this file i get the following files: its.zip, log.html, metadata.properties, portal.zip and upgrade.xml. As I have understood it that is the correct content. Now I'm supposed to unzip the file "portal.zip" and reach amongst other folders the one named "prtl". In this one there is a folder named "images" and under that one is "header" found and in THAT folder the change of picture is done.
    Now for the problem: when I unzip "portal.zip" I just get the content of some property file, NO folders what so ever! If I try to unzip "its.zip" I can see the folder structure under that folder!
    If I open the structure with Total Commander I can see the missing folders! But I can't do the copying of the image, the whole structre gets duplicated when I save! I thought the zip file was corrupt so I made another copy and downloaded it but with the same result!
    Has anyone had the same problem???
    Best regards
    Benny Lange

    Problem solved! By 7-zip. It was actually XP's integrated zip tool that just didn't show the underlaying structure. And Total Commander also did the work if used in the same way as 7-zip, but to edit the second level zip file directly did not work as TC opened that file in a temp directory instead of continuing at the level of the first zip file. That kind of editing directly in a file two zip levels down actually worked in TC 6.x but now I have 7.05 and perhaps things has changed.

  • Opening a zip file from Mail - what should happen?

    I've been using a Mac for a little under a week so bear with me...!
    I receive a zip file in Mail and I want to open it, so naturally I click on it. I get a "may contain an application" warning. I click "Open". A window briefly appears with an "Unarchiving" progress bar, then vanishes. And that's it!
    Is this expected behaviour, or has something messed up here (most likely me!)? I would expect some sort of helper application to open showing the zip contents maybe?
    Thanks!
    Matt

    Hi Matt,
    Welcome to the discussions and to Macs!
    Zip has un-zipped the attachment contents into the place where the zip file was kept. Often that's a clever thing for it to do, but in this case the location is a place Mail chose rather than you!
    You might look in <home>/Library/Mail Downloads. If not, use Spotlight to search for the zip file by name. That directory will also hold the unzipped contents.
    Next time: Drag the zip file from the email to your desktop, then double-click it to unzip. The contents will show right up on the desktop too.
    Good luck,
    John

  • Socket blocking on read operation while uploading zip file to the server

    I am trying to upload a zip file to the server
    Client thread creates the zip file ( of the modified files) and it even completes writing the data to the socket stream.
    Now if the server thread tries to read the same data from the stream, it blocks on read operation.
    While downloding the zip file from the server works fine.
    Thanks in advance

    You can use the URL object to upload it as multipart/form-data.
    http://forum.java.sun.com/thread.jspa?threadID=579720&messageID=3997264
    Or check out some of the file uploaders out there.
    http://www.google.nl/search?hl=nl&q=site%3Asun.com+upload+applet&btnG=Zoeken&meta=

Maybe you are looking for

  • Error while using dbms_lob.fileopen

    Hi, I am getting the below error when executing the code given below, CODE:- DECLARE l_bfile BFILE; l_data BLOB; BEGIN DBMS_LOB.createtemporary (lob_loc => l_data, CACHE => TRUE, dur => DBMS_LOB.CALL); l_bfile := BFILENAME('/home/lt/write','MIA00137.

  • FTPS failing with Error: ...FTPEx: 'AUTH TLS': command not understood !!

    Hi, I am trying to send a file over FTPS (FTP using SSL/TLS) . But it fails with the following error in RWB - Communication Channel monitoring: Error when getting an FTP connection from connection pool: com.sap.aii.af.lib.util.concurrent.ResourcePool

  • IBook only on iPad ??

    In the iTunes stored, iBook "The Shoah" by Brian Hurd says it's only available for iPad.  Is it true that iTunes on my Mac will not accept it as a book?

  • Problems with Restore

    I did a backup on my iPhone 4S prior to trying to updated to iOS6. I have it setu[ to backup to the cloud. I tried to update to iOS6 but it failed. itunes showed the option to restore from my backup which I attempted to do, but it asks for a password

  • Adding a new input field on selection screen after input in a select option

    Hi Experts, There are 2 input fields on the selection screen. I would like to add a new select option field when a value is entered in the 2nd field <b>only</b>. If there is an input in the 1st field or both the fields, the new input field should not