Zip file is created with 0 bytes

In my below code, I am trying to zip a folder containing files and folders. But the zip file is getting created with 0 bytes.
Could anyone please tell me what is wrong in my coding.
private void jButton5ZipActionPerformed(java.awt.event.ActionEvent evt)
     File sgm=new File(jTextField1Text);//jTextField1Text is the filename I am selecting from the jTextField
     File tempXML=new File(sgm.getParent());
     String[] children = tempXML.list();
     for(int i=0;i<children.length;i++)
          File renamingFile=new File(tempXML,children);
          CreateZipFile czf=new CreateZipFile();
          try
               czf.doCreate(renamingFile);
          catch (FileNotFoundException ex)
               ex.printStackTrace();
          catch (IOException ex)
               ex.printStackTrace();
==============================
void doCreate(File dir) throws FileNotFoundException, IOException
     String[] filenames=new String[]{dir.toString()};
     byte[] buf = new byte[1024];
     try
          // Create the ZIP file
          String outFilename = "C:\\outfile.zip";
          ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outFilename));
          for (int i=0; i<filenames.length; i++)
               FileInputStream in = new FileInputStream(filenames);
               // Add ZIP entry to output stream.
               out.putNextEntry(new ZipEntry(filenames[i]));
               // Transfer bytes from the file to the ZIP file
               int len;
               while ((len = in.read(buf)) > 0)
                    out.write(buf, 0, len);                    
               // Complete the entry
               out.closeEntry();
               in.close();
          // Complete the ZIP file
          out.close();
     catch (IOException e)
Message was edited by:
Simmy

If I give File [] filenames =
dir.listFiles();an error is thrown for the line
out.putNextEntry(new
ZipEntry(filenames)); as
cannot find symbol
symbol: constructor ZipEntry(java.io.File)
location: class java.util.zip.ZipEntry
There's no constructor that accepts a File as argument. There's only this
ZipEntry(String name)
          Creates a new zip entry with the specified name.
ZipEntry(ZipEntry e)
          Creates a new zip entry with fields taken from the specified zip entry.
Check the API
http://java.sun.com/j2se/1.4.2/docs/api/java/util/zip/ZipEntry.html
regards,
MAnuel Leiria                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • Why is my Zip file being created with size of O KB?

    I have the following code
    public static int createZip (String directory)
                       throws IOException {
         File path = new File( directory );
         File outZip = new File("c:\\wip\\sams9dbExport.zip");
         boolean boo = outZip.createNewFile();
         FilenameFilter filter = new FilenameFilter() {
            public boolean accept(File dir, String name) {
                return name.endsWith(".xml");
        if ( outZip.exists() ) System.out.println("File exists");
         System.out.println(" Files and filters made");
         // These are the files to include in the ZIP file
         String[] fileList = path.list(filter);
        // Create a buffer for reading the files
        byte[] buf = new byte[1024];
        try {
            // Create the ZIP file
            String outFilename = "sams9dbExport.zip";
            ZipOutputStream out = new ZipOutputStream( new FileOutputStream( outFilename ) );
            // Compress the files
            for ( int i=0; i < fileList.length; i++ ) {
                FileInputStream in = new FileInputStream( "c:\\wip\\"+fileList[i] );
                 System.out.println( fileList[i] );
                // Add ZIP entry to output stream.
                out.putNextEntry( new ZipEntry( "c:\\wip\\"+fileList[i] ) );
                System.out.println("Added an entry");
                // Transfer bytes from the file to the ZIP file
                int len;
                while ( ( len = in.read( buf ) ) > 0 ) {
                    out.write( buf, 0, len );
                // Complete the entry
                out.closeEntry();
                in.close();
            // Complete the ZIP file
             out.close();
        } catch (IOException e) {
             System.out.println( e.toString() );
             return 0;
        return 1;
    }And I get the following output
    SQL> @ziptest
    File exists
    Files and filters made
    AH_QUERY.xml
    Added an entry
    myclob.xml
    Added an entry
    myclob1.xml
    Added an entry
    myclob2.xml
    Added an entry
    PERSONNEL.xml
    Added an entry
    PERS_ALG.xml
    Added an entry
    sampledoc.xml
    Added an entry
    ut_ah_query1.xml
    Added an entry
    ut_provider.xml
    Added an entry
    PL/SQL procedure successfully completed.
    SQL>
    But my file is created empty. I previously added a println statement in the while loop to see if it was reading and writing bytes and it was.
    Any ideas?

    I have the following code
    public static int createZip (String directory)
    throws IOException {
    File path = new File( directory );
    File outZip = new
    = new File("c:\\wip\\sams9dbExport.zip");
    boolean boo = outZip.createNewFile();So these two lines will create sams9dbExport.zip with size 0 bytes, if file didn't exist.
    No need to do that....
    try {
    // Create the ZIP file
    String outFilename = "sams9dbExport.zip";
    ZipOutputStream out = new ZipOutputStream(
    tStream( new FileOutputStream( outFilename ) );Probably you are looking a wrong "sams9dbExport.zip" -file. Your application will create two "sams9dbExport.zip"-files, one into wip-folder with 0 bytes, and other into default directory.
    >
    But my file is created empty. I previously added a
    println statement in the while loop to see if it was
    reading and writing bytes and it was.
    Any ideas?

  • Unable to find ODI_SAmple_DATA.zip file to work with oracle profiling.

    I am unable to find ODI_SAmple_DATA.zip file to work with oracle profiling.Any help regarding profiling???Do i need to
    copy it from sw installation folder.?How profiling is different or related to odi data quality???Do we take source data twice -
    1) For ODI target load
    2)For profiling into entities.

    Try:
    http://www.oracle.com/technology/products/oracle-data-quality/pdf/oracledq_sample_data.zip
    and
    http://download.oracle.com/otn/nt/ias/101340/oracledq_sample_directory.zip
    Hope this helps.
    G

  • I am facing issue when opening flash files in Flash CC. (error:- This file was created with a later release of Flash Professional and might contain new features that would be lost when saved in the current format.)

    I am facing issue when opening flash files in Flash CC. (error:- This file was created with a later release of Flash Professional and might contain new features that would be lost when saved in the current format.)

    Wow. Okay...
    I'll let the real veterans in this forum tackle your issues one after the other. But, I can tell you, all will be well.
    My only comment would be re: your computer specs:
    BJReis wrote:
    .  This may be due to somewhat older equipment:
    GHz Intel Core Duo MacBook Pro with a 4GB memory computer with Ddr3 running OSX 10.8.4
    To be completely honest, FCPX is a RAM hog. It just is. But, RAM is relatively cheap, and the pay-off is good.
    4GB is right on the edge, IMHO. 16G is ideal.
    I wish you luck, hang in there, and standby for more help.

  • Files/projetc created with PRemiere 6.5. Supported by PRemiere Element 9 ?

    Hi all,
    I think to change my old powerbook G4 for an Imac intel core duo.
    What about my files/project created with Premiere 6.5 if I want to open them with Adobe Premiere Element 9 ?
    Is it possible ? Can i still work/modify them ?
    Regards,
    A.

    I would recommend contacting Adobe for that answer, your question is about their software so I would think they would be the best people to ask.
    Roger

  • Are cp file extensions created with Captivate 4  compatable with Captivate 8?

    Are cp file extensions created with Captivate 4  compatable with Captivate 8?

    Hi there
    I believe you will need a copy of version 5 or 6 to open the CP with and convert to a CPTX. Then you can open using 8.
    Additionally, you may discover that things become a bit mangled during the upgrades. Many have not gone smoothly and have forced a rebuild of the project.
    Cheers... Rick

  • Duplicate text files being created with ~ appended

    Whenever I edit a text file with TextEditor and save it, a duplicate file is created with a ~ appended to the end of the name.
    Example:
    After editing and saving my_file.txt my_file~.txt is also created.
    The result is I get two files with exactly the same contents.
    my_file.txt
    my_file~.txt
    I would really like to stop it from doing this. It clutters up everything. It has done this since I first installed the OS. My file system format is Mac OS Extended (Journaled). Any suggestions?

    I looked through the preferences for TextEditor. I had "Delete the automatic backup file unchecked". I think checking this option will fix the problem.

  • How to prevent unauthorized extraction of the zip files I created.

    Hi all,
    Can anyone help me in knowing abt this.
    Is there any way to prevent unauthorized extraction of the zip files I create using Java.
    Plz help friends.
    Thanks in Advance.
    -James

    Since you already found out that Java's zipping methods don't implement password protection, all you could possibly do is encrypting the contents.

  • Fusion Order Demo zip file which works with JDeveloper 11.1.1.3.0

    Hi,
    Please can anyone tell me where to find the Fusion Order Demo zip file that will work with JDeveloper 11.1.1.3.0 (latest version 13/5/10).
    I have downloade OracleXE 10g for Windows on my laptop and now want to create the Fusion Schemas (Tables/Schemas/Procedures etc) for the Demos.
    I have downloaded FOD_11.zip, FusionOrderDemo_R1.zip and tryed the instructiion for running Fusion Order Demo here http://www.oracle.com/technology/documentation/jdev.html but each time I get the error
    "oracle.javacache_11.1.1 not found"
    How can I fix this?
    I want to learn Jdeveloper works and use it for Logical and Physical Schema mapping....
    Thanks
    BP

    Hey John,
    Thanks for the quick reply, and yes sir, I did follow those instructions.
    Let me describe what all I have done so far, maybe someone can figure out where I need to fix anything:
    I installed JDeveloper version 11.1.1.3.0, which came with its own WebLogic server, on my windows xp professional OS on my laptop.
    I then downloaded the zip file, FusionOrderDemo_R1PS2.zip.
    I encountered a problem while unzipping the file, where it was asking me some password for a few files, but Lynn from Oracle helped me figure that out....i had to use 7-zip utility to uninstall....windows default built-in unzip utility does not work.
    After unzipping all files, I followed the instructions given on http://www.oracle.com/technetwork/developer-tools/jdev/index-095536.html to import, build and run the application....
    And now when it runs....it just open my browser window (IE 7), and shows a "loading..." image in the center of the page....nothing happens after that.
    Any idea what might be missing?
    a few major errors I see in the wls log window of jdeveloper are:
    1) <DCBindingContainer><reportException> [3952] oracle.jbo.JboException: JBO-29000: Unexpected exception caught: java.sql.SQLDataException, msg=ORA-01882: timezone region not found
    2) <DCBindingContainer><reportException> [3958] oracle.jbo.JboException: JBO-29000: Unexpected exception caught: java.lang.NullPointerException, msg=null
    3) <UIXInclude><tearDownVisitingContext> Tear down of include component context failed due to an unhandled exception.java.util.NoSuchElementException
    Please help!
    Regards,
    Hemant

  • Corrupt (?) zipped files from "Create Archive"

    I am repeatedly having trouble with files I zip using "create archive." Whether it's fonts or images, the recipients are not able to use the files I send (they seem to uncompress, but aren't readable). This is happening often enough that I wonder if there is a problem with the software. I didn't find this question asked when I did a search.
    thanks!

    Hi, casperr. Welcome to the Discussions.
    1. Are the recipients using Windows? If so, you may want to purchase a copy of StuffIt Deluxe, which can create archives that are both Windows-friendly and self-extracting.
    2. Have you tried opening the archives you have created with Create Archive to see if the contents of the archive you've created are AOK before sending them? That will help you determine if the problem is on your Mac, with the transmission, or a problem on the other user's computer.
    3. You might want to enquire as to how the recipients are unzipping the archives you have sent that they are finding problematic.
    Good luck!
    Dr. Smoke
    Author: Troubleshooting Mac® OS X

  • Cant get list of files from a folder (even though the folder and files are created with the same app)

    Ok so each character rolled with my app gets saved as an html file in a folder i create on the sdcard called RpgApp
    the code to do this is 
    private async Task saveToHtmlCharacter(string name)
    StorageFolder externalDevices = Windows.Storage.KnownFolders.RemovableDevices;
    StorageFolder sdcard = (await externalDevices.GetFoldersAsync()).FirstOrDefault(); //Windows.Storage.ApplicationData.Current.LocalFolder;
    var dataFolder = await sdcard.CreateFolderAsync("RpgApp",
    CreationCollisionOption.OpenIfExists);
    var file = await dataFolder.CreateFileAsync(name+".html",
    CreationCollisionOption.ReplaceExisting);
    using (StreamWriter writer = new StreamWriter(await file.OpenStreamForWriteAsync()))
    writer.WriteLine("<html><head><title>Character File for " + z.charNameFirst + " " + z.charNameSecond + "</title></head><body>");
    //trimed for the post
    now this as i say works perfectly and i can confirm that the files show up in the "RpgApp"folder
    now the next step is to have the app read the names of each of those html files and create a seperate button for each one named for the filename and with the filename as content (later i will link them up to load the html file they are named for in a webbrowser
    panal)
    here is the code that *should* do that
    private async Task readFiles()
    z.test.Clear();
    StorageFolder externalDevices = Windows.Storage.KnownFolders.RemovableDevices;
    StorageFolder folder = (await externalDevices.GetFolderAsync("RpgApp"));
    IReadOnlyList<StorageFile> fileList = await folder.GetFilesAsync();
    //z.test.Add("dummy");
    foreach (StorageFile file in fileList)
    z.test.Add(file.Name);
    public async void buttonTest()
    await readFiles();
    CoreDispatcher dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
    await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
    foreach (string name in z.test)
    Button button1 = new Button();
    button1.Height = 75;
    button1.Content = name;
    button1.Name = name;
    testStackPanal.Children.Add(button1);
    now i say should as what i get is an error of "A first chance exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.ni.dll" (2 of them in fact one after another)
    more detailed error is at http://pastebin.com/3hBaZLQ9
    now i went through checking line after line to find the error and line that causes it is:
    StorageFolder folder = (await externalDevices.GetFolderAsync("RpgApp"));
    in the readFiles method
    i checked to make sure the case is right etc and its spot on, that IS the folder name, and remember my app creates that folder and creates the files that are inside that folder (and only files my app creates are in that folder) so it should have access
    im 100% stuck its taken me all day to get the files to save and now i cant get them to list correctly
    I have tested the button creation function with fake list data and that worked fine, as i say the error is when i tell it to look at the folder it created
    all help most greatfully recieved

    this was actually solved for me on another forum thread 
    async Task<bool> continueToReadAllFiles(StorageFolder folder)
    if (folder == null)
    return false;
    if (folder.Name.Equals("RpgApp", StringComparison.CurrentCultureIgnoreCase))
    var files = await folder.GetFilesAsync();
    foreach (var file in files)
    test.Add(file.Name);
    return false;
    var folders = await folder.GetFoldersAsync();
    foreach (var child in folders)
    if (!await continueToReadAllFiles(child))
    return false;
    return true;
    public async void buttonTest()
    test.Clear();
    StorageFolder externalDevices = Windows.Storage.KnownFolders.RemovableDevices;
    var folders = await externalDevices.GetFoldersAsync();
    foreach (var folder in folders)
    if (!await continueToReadAllFiles(folder))
    break;
    //.... commented out
    ...now i say solved this is more a workaround...but it works.
    I would love to know why we cant just scan the RpgApp folder instead of having to scan the whole dc card and disregard all thats not in the RpgApp folder

  • Xref table is missing when a pdf file is created with acrobat distiller 9.0.0

    Hi
    I created a pdf file with the new acrobat distiller 9.0.0 and i noticed that the xref table is missing in it.
    Whereas the pdf files which created in older version (acrobat distiller 7.0.5) had the xref tables.
    As i have written a perl script to open the pdf files (used a ready made module downloaded form cpan.org). The script works fine with all old pdf files but fails when it tries to open the pdf files created with distiller 9.0.0.
    Could i know is any thing changed on acrobat distiller 9.0.0 ?
    Thanks
    Balaji.

    PDF documents of version 1.5 and higher can contain cross-reference streams. Read the PDF Reference.

  • Files not created with iTunes do not play from remote iTunes library

    I hve ripped a large part of my CD collection into music files into FLAC format. I have since converted my music files from FLAC into Apple Lossless Audio Codec (ALAC) format and imprted them into iTunes.
    The files play with no problem on iTunes if they are on a local iTunes library. Furthermore, all metadata such as tags and album cover art information are properly displayed in iTunes. This is true whether I'm running iTunes on a Windows XP box or a Mac OS X box. I have since imported many other CDs into my iTunes library using iTunes to encode into ALAC.
    If I share the iTunes library on my Windows XP machine to iTunes running on a Mac OS X box or to an Apple TV, I can:
    *play songs that were imported directly using iTunes
    *not play any songs that were not created with iTunes
    This behavior is true whether I'm trying to play them from either a Mac or from an Apple TV.
    If I copy the *.m4a files to the Mac and import them to the iTunes library I have no problems playing them on the Mac. I have not tried sharing the iTunes library on the Mac and tried accessing the files from the Apple TV or the Windows PC.
    Any thoughts?

    Fix: optimize m4a files moving the meta data to the beginning, whilst optionally creating a hint track (used for streaming m4a over Apple Airtunes).
    see: http://www.dbpoweramp.com/codec-central-m4a.htm

  • Ya, try to download a 700 MB zip file !! with whatever available means

    Please a bit more commercial efforts, even if your name is ORACLE
    Because at the end it is in your interest !!
    Have you ever tried to download a 700 MB zip file !! to your private PC ? Me, I don't even dare to try!

    What is your question? I downloaded them without problems? Obviously if you are on a dial-up connection this is not an option.

  • This file was created with a newer version of Adobe After Effects

    I downloaded the trial version of Adobe After Effects last night and spent a lot of time learning how to use the product, created my first tracking face on a body in a video.
    This morning when I tried to open the project I got an error message: After Effects Error: this file was created using a newer version of After Effects [3.0 (unknown)] -- time to upgrade your application!
    What should I do?

    Sounds odd. If you created it in CS6 it should open just fine in that same version. chances are that the project fiel is simply damaged. Impossible to tell without actualyl seeing the file.
    Mylenium

Maybe you are looking for

  • Error While Installing the Business Content Query

    Dear Friends, We are in BI 7.0 and trying to install a business content query "Balance Sheets Profit and Loss Statement" but while activating we are getting the error that some Particular Request has not been found or not suitable. we checked for tha

  • Document Type PHP quite working

    am using dreamweaver cs4 runing under window vista. I have two websites that uses php/mySQL to interact with databases.  Both were built with dreamweaver cs4 on this same computer.  Both have been up and running for some time. Today I needed to make

  • List display- PDF- email

    Hi Folks,   can someone please share how to convert an list display to PDF in LANDSCAPE then email as attachment. Best Regards, Babu Moderator message: FAQ, please search for available information/documentation. Edited by: Thomas Zloch on Jul 12, 201

  • Sharing pictures from iphoto to NON-apple users

    Can you share pictures from iPhoto to people that don't have an apple device? Everything I have found says they must have an apple device. I am trying to share a bunch of pictures to a friend that has a Window-based computer. Thanks

  • HELP! Creative Cloud Blank Screen Windows 8.1

    Whenever I try and open creative cloud, all I see is a blank white screen (picture below). I have tried renaming the OOBE folder but nothing has worked. I am running on a windows 8.1 64bit pc with an NVIDIA GeForce 860m graphics cards. The whole reas