Problem with Java and Zip Files

Hello there everyone. I have a problem with trying to zip up directories with empty folders in them. They zip fine with my code, but according to winzip, the number of files in the archive is incorrect. It's supposed to have a total of 288 files in it, but when it's zipped up, it only says 284. I mention specifically the "empty directories" note because the zipping works fine without empty folders.
Below is the code for the zip method:
public static void zip(File[] list, File zipfile, File zipRoot)
     throws IOException {
      if (!zipfile.exists()) {
               zipfile.createNewFile();
          else if (!zipfile.isFile()) {
               throw new IOException("The zip file, " + zipfile.getAbsolutePath()
                         + " is not a file.");
          if (list.length == 0) {
              LOG.error("The list of files to zip up is empty.");
          for (int i = 0; i < list.length; i++) {
               if (!list.exists()) {
                    throw new IOException("The file or directory, " + list[i].getAbsolutePath()
                              + " does not exist.");
          FileOutputStream fos = new FileOutputStream(zipfile);
          ZipOutputStream zos = new ZipOutputStream(fos);
          for (int i = 0; i < list.length; i++) {
               if (LOG.isDebugEnabled())
                    LOG.debug(i + ": " + list[i].getName());
               String entryName = getRelativeName(list[i], zipRoot);
               if (list[i].isDirectory()){
                    if (list[i].listFiles().length == 0){
                         ZipEntry entry = new ZipEntry(entryName + "/");
                         zos.putNextEntry(entry);
               else {
                    ZipEntry ze = new ZipEntry(entryName);
                    zos.putNextEntry(ze);
                    byte[] buffer = new byte[8096];
                    FileInputStream fis = new FileInputStream(list[i]);
                    int read = 0;
                    read = fis.read(buffer);
                    if (LOG.isDebugEnabled())
                    LOG.debug("\tFound " + read + " bytes.");
                    if (read == -1){
                         //empty file, but add it for preservation.
                         //zos.write(buffer,0,0);
                    while (read != -1) {
                         zos.write(buffer, 0, read);
                         read = fis.read(buffer);
                    fis.close();
                    zos.closeEntry();
          zos.close();
The files look like they're there, but I need the system to be able to determine the number correctly. 
Here's the interesting thing:  It zips the files, and then when I use the size() method for zip files in java, it says 284 files.  But when I unzip, it says 288 again.  It's like there's files missing when compressed, but when decompressed, they return.  Note that the files are actually there.  If I open the archive in a third party app such as Winzip AND Winrar AND IZarc, they all show 288 files.  Any idea what would make the number of files appear incorrectly in a zip file when zipped by java with the code above?  Thanks in advance.
- Chris                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

I figured out the problem. When zipping files in windows using winzip, it doesn't explicitly count folders as a "file/folder" as a file in itself. It will create the folders for files to go in, but the folder itself will not be 'counted' when you query the info of the file itself. You have more control of the zip file in java, and can count the folder as a file or not.

Similar Messages

  • Problem with Preview and PSD files - random gray square

    Hi guys, hope you can help...
    I've got a problem with Preview and PSD files.
    If I open in Preview both an original jpg straight from my reflex and the photoshop version of the same picture, the psd file presents a gray square (of what it seems unrendered image) in a random area of the photo (sometimes in the center.). The square is quite big...
    If I zoom in or zoom out it disappears...if I scroll to another photo and then back to the psd, the square it's there again...sometimes in a different position.
    I've tried the same psd on my older iMac with leopard...and got no problem at all.
    I suspect it got something to do with my Ati...
    (this is the second iMac 27...the first went back for gray banding on the lcd screen and flickering and yellow tinge........)
    Thanks for your help.
    DAve.

    maybe I'm onto something...
    I've just found out that opening Preview in 32bit mode (instead of default 64bit) works flawlessly with any psd files. If I switch back to 64bit mode, Preview is much faster but the gray square comes back...
    It seems like the i7 is much faster than the Ati....
    Any more realistic ideas?

  • Problem with java and pogo games

    i use mozilla and now with the problems with java and hackers cannot play my pogo games,what can i do? i disabled my java i tried java 6 doesnt work or is not safe,what is a safe way to play games on pogo that use java?

    Oracle has released a Java 7 Update 11 to address security vulnerabilities and you should update to that version.
    *https://support.mozilla.org/kb/how-to-use-java-if-its-been-blocked
    See also:
    *http://kb.mozillazine.org/Java#Windows_installation_issues
    You can find the latest Java version on the Oracle website.
    See Java Platform > Java SE 7U11 and Java 6U38 (Download JRE)
    *http://www.oracle.com/technetwork/java/javase/downloads/index.html

  • Problem in tutorial and zip file. can anyone file it or correct it..

    hi jdev experts,
    am using jdev11.1.1.5.0.
    when am new to these webservice. i followed this tutorial
    http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_14/jdtut_11r2_14.html
    url wsdl link when use that wsdl.
    throws some error.
    what is the reason john says. ok at second post of the thread.
    Consuming a Web Service from a Web Page
    so if i change the wsdl means and somethings has to be changed in tutorial steps.
    if any newbie crossing this tutorials feels very difficult to work. so can change the wsdl url link and those steps.
    and another thing I installed 11.1.2.0 and download that zip file in that tutorial and i run throws the same error.
    so. problem in tutorial and zip file. can anyone file or correct..
    i think think this is the right place to tell this. or else re-direct me.

    this is to arun.
    As the exception stack clearly mentions that the endpoint is moved, it is up to the users to make use of any other webservice.trace says link is moved i know.
    thing am here is:
    please make note on that tutorials.
    * note :- just like this consume some other external webservices. dont use this webservice this webservices link is broken.
    this what saying.
    this to john.
    thanks. thanks again.

  • Discussion Forum Portlet - Problems with JAVA and UTF8?

    Hi
    I installed the Discussion Forum Portlet successfully. It also seems that almost everything works fine. There's only a problem if I have new posts that include special German characters (Umlaute) like ä, ö, ü or special French characters like é, è or ç. They are saved correctly in the table but if you view the post the characters are not displayed correctly.
    Example
    input: ça va?
    result: ça va?
    I know that there are problems with Java and UTF8 Database. Is there a possibility to change this (bug)?
    Regards
    Mark

    Here's what I got. I don't see anything that helps but I'm kinda new to using SQL and java together.
    D:\javatemp\viddb>java videodb
    Problem with SQL java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver
    ] Syntax error in CREATE TABLE statement.
    Driver Error Number-3551
    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in
    CREATE TABLE statement.
    at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbcStatement.execute(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(Unknown Source)
    at videodb.main(videodb.java:31)
    D:\javatemp\viddb>

  • Problem with Java and Windows (Mainly Vista and UAC)

    Hi all,
    I am having a problem with a program that I've devoloped. The program itself is packaged as a jar and I plan to deploy it across multiple platforms eventually however right now i am only concerned about windows based systems. I have made an installer for a windows baised systems using NSIS to install the software files. I made the installer as I need several java packages to be installed so the program would work (JAI, J3D, JAI ImageIO) and I also require the program to have fileassociations on windows.
    I know that this is not what java is about, however the majority of the users will be on windows baised systems so I've decided that OS specific installers is the best option.
    During the process I have noticed that there are several key problem with java for this type of application!
    The first issue that I have come across is getting file associations to work on java. As a .jar is not an excutable it is not possible to directly associate a filetype with it in java so to overcome this I currently run the program from a .bat files and also the program requires large memory so this also allows me to run the program with -xmx. The batch file that I use is :
    <code>
    cd PATH TO PROGRAM
    start javaw -Dsun.java2d.noddraw=true -Xmn100M -Xms500M -Xmx1000M -jar "PATH TO PROGRAM\program.jar" %1 -vram 134217728
    pause;
    </code>
    Ok so all this appears to work fine and allows windows to have file associations and start the program and thats all works perfectly but this is a non-ideal solution. Has anyone got any advice on improving this?
    The next problem that I have appears to be a problem with Vista and UAC (user access control). When a user installs the program and installs the program into the program files directory I found that the program did not work and kept saying that I did not have access to the files in the current directory. This is a problem as I read and write settings files during program execution.
    On a Vista system UAC prevents file write operations into the Program Files directory unless the program has requested elevated status even if the user is a full administrator. The probem is that there appears to be no real way to achieve this under java that I'm aware of...
    Has anyone else had this probem and has a suitable solution?
    Any advice on these issues would realy be appricated.
    Regards
    Joey

    Ok so i've kinda found a solution, its not ideal but its very good. I found this program called Elevate
    A link to the site I got it was
    http://www.wintellect.com/cs/blogs/jrobbins/archive/2007/03/27/elevate-a-process-at-the-command-line-in-vista.aspx
    This program allows you start java with a UAC dialog for high access using
    Elevate java -jar myjar.jar
    This then allows you to have full access using java... I guess it could be dangerous but it does the job.

  • I have a problem with Java and an e-procurement system integrating

    I use an e-procurement system at work and yesterday I could not get my parts list from the suppliers web site to display in our in-house eprocurment finance package.
    There is not a problem with the finance package. There is not a problem with the suppliers web site. I have verified both of these by other colleagues being able to complete what I am trying to do.
    The difference between my version of Firefox and my colleagues' is that I am on version 6.0.1 and they are on 6.0.
    I have had problems with Java not displaying certain animations on the suppliers web site but, my colleague does not and I am suspicious that this is the problem. Can anyone verify this please and what can I do about it. My Java updates are up-to-date as of yesterday and are automatic.
    Thanks.

    I was quite amazed I never got a reply to this, in the past people here have been helpful. In any case I was finally able to enter this website on the exceptions list in the Java panel, and I believe it is okay  now.

  • Events problem with (Java and ActiveX)

    Hi,
    I use an ActiveX component with Java and i've got a problem with events.
    Java classes were generated with Bridge2Java (IBM).
    In order to manage events I added a listener in my application :
         javaMyActiveX = new MyActiveX();
         javaMyActiveX.add_DMyActiveXEventsListener(new _DMyActiveXEventsAdapter());
    I also added a constructor in the _DMyActiveXEventsAdapter class and I fill the body of methods.
    The ActiveX generates two types of events :
    - The ones are directly generated by methods.
    - The others are generated by a thread.
    With MS Products (VB, Visual C++, Visual J++), I catch all events.
    With java (jdk 1.4), I catch only events generated by methods.
    Can anyone help me.

    I'm not 100% sure, but the last time I used that bridge, it only worked if you ran your Java app within a Microsoft VM.

  • I am having a problem with Java and Abode. Trying to play Pogo.

    Every time I try and play Pogo I have a problem. It pops up with a message about Java. If I hit the button it says to activate add on's which I try and do and now it will not do anything. Is my problem with Firefox or pogo. It seems that most of the problem is abode because it pops up every where.

    Please check if all your plugins are up-to-date. To do this, go to the [http://mozilla.com/plugincheck Mozilla Plugin Check site].
    Once you're there, the site will check if all your plugins have the latest versions.
    If you see plugins in the list that have a yellow ''Update'' button or a red ''Update now'' button, please update these immediately.
    To do so, please click each red or yellow button. Then you should see a site that allows you to download the latest version. Double-click the downloaded file to start the installation and follow the steps mentioned in the installation procedure.

  • Problem with Java and Outlook

    I am having a problem with the Java plug-in and Microsoft Outlook 2003. When I have Outlook running, going to certain websites (like cbs.sportsline.com/collegefootball) will crash my browser (IE). I get a message like this:
    An unexpected exception has been detected in native code outside the VM.
    Unexpected Signal : unknown exception code (0xe06d7363) occurred at PC=0x77E73887
    Function=RaiseException+0x50
    Library=C:\WINDOWS\system32\kernel32.dll
    There is much more to the error message which appears as a text file on my desktop. If I close Outlook and try to go to that same CBS site, it works just fine. Has anyone else experienced this? Is there a solution?

    In Window, the dlls are not private to one
    application. They are logically shared. Not true in the sense that would affect this. DLL Text (code, read-only data in some cases) is shared. DLL Writable data is NOT shared between apps - each app gets its own copy of the data pages.
    However, it's possible that when Outlook runs, it interacts with IE (which has deep tentacles into the system) in such a way that when Java calls into native IE code, it is affected as an innocent bystander.
    Make sure you also install all the Office patches. If that doesn't help, try upgrading your Java VM to the latest version (you are using the Sun VM, right?).

  • Problems with java.util.zip

    I've got a odd problem here. I'm not sure if this is the appropriate forum but I couldn't find anyplace more appropriate.
    So the problem is...
    I create my ZIP file and if I open it in WinZip, no problem. But if I open the ZIP file using the 'Compressed Folders' feature of Windows Explorer I don't see any of the files. As far as I can tell, if the files I ZIP up do not contain any path information then they open fine via 'Compressed Folders'.
    Is this a bug in java.util.zip? Or is the 'Compressed Folders' feature in Windows Explorer half-baked?
    And finally is there any way for me to not include the path information of the files added to ZIP?
    Thanks.

    Looce:
    I'm more than willing to modify things.
    But I'm still curious why WinZip and Windows are treating the ZIP files differently.
    Also, the only way I can figure to get the files into the ZIP without the path information being stored in the ZIP file is by copying the files to the directory containing my application jar file and then passing in the file name without the path being specified. That is the only way FileInputStream would be able to find the files without including path information. This seems like a lot of unnecessary overhead.
    Another oddity is that if I create the ZIP archive using the file path for the FileInputStream and view the ZIP file using a HEX editor the entire path is being stored including the drive letter. But if you view the file using WinZip the path field seems to be removing the drive letter and only displaying the path. On top of that, even though the drive letter is contained in the archive if you unzip the file using WinZip it ignores the drive letter and unzips the file to whatever drive the archive is located on. In the grand scheme of things it makes sense for WinZip to ignore the drive letter.
    Thanks for you help anyways.

  • Problems with jdbc and .jar files.

    I am having a problem with connecting to my database when running my .jar file as an executable.
    It connects correctly when I use the java command in command prompt and it also runs correctly when using my IDE.
    Is there something that needs to be added to the manifest or in the code it self inorder for the program to find the JDBC driver correctly?

    This is the error message that I get:
    java.lang.ClassNotFoundException: net.sourceforge.jtds.jdbc.Driver
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at AboutFrame2$Connect.getConnection(AboutFrame2.java:109)
    at AboutFrame2$Connect.displayDbProperties(AboutFrame2.java:127)
    at AboutFrame2.<init>(AboutFrame2.java:72)
    at MainStartFile2.main(MainStartFile2.java:7)
    Error Trace in getConnection() : net.sourceforge.jtds.jdbc.Driver
    Error: No active Connection
    I think that it is because it cannot find the driver. I am going to add the path to the manifest and see if that works thank you for all the help.

  • Problem with creating a ZIP file

    I have a program that uses java.util.zip to zip all the files in a user's directory (aproximately 7 files totalling 2 MB). When the files are extracted later using WinZip or a similar tool, the files appear to be the same (same file size & date), but they can not be opened by the program that uses them. When I use a binary diff tool to compare the before zip and after zip files, it shows about 20 random bytes that have changed. Anybody else seen this occur?
    Thanks

    Hi,
    I am successfull in putting all the files of a
    directory in a newly created ZIP file. But if my
    directory has a sub-directory, it's not workin....m
    not able to zip it properly. I mean, my program is
    doin it withour error but when i try to open it using
    WinZip...it's giving me an error sayin as not a proper
    archive...
    Do anyone have faced this problem??
    GauzYou need to call the following functions of ZipOutputStream after completing zipping in your code ?
         objZipOutputStream.finish();
         objZipOutputStream.close();Also for every file being zipped, you should to call
    objZipOutputStream.closeEntry()to close that zipEntry.
    Hope this helps.

  • Problem with java and flex web service

    Hi,
    I have a basic web service written in java using jax ws 2.1
    ri. I need to call it from Flex using the WebService class
    Annotations for the java web method :
    @WebMethod
    public void Login(
    @WebParam(name="server") String serverURL,
    @WebParam(name=AUTHENTICATE_HEADER,header=true,mode=WebParam.Mode.INOUTHolder<Authenticate Header>
    authHeader)
    When I try and call the service from Flex , it can't find the
    login method and attempts to call it fail. If I set the web service
    to RPC based using @SOAPBinding , the method is found but then
    there are issues with the authentication header.
    What do I need to do to get flex web services communicating
    succesfully with java ?
    Are there are any known compatibility issues ? Or guidelines
    for going about this ?
    Any help would be appreciated

    well Shay,
    i've used JDev's tools to developer and to deploy the web service: the war and ear files are automatically generates you to the end of the process.
    I have included all the files java and the compiled classes, but I do not have files jar.
    But don't works: if i create only one java class with all code inside then it works fine!!
    Daniele

  • Problem with java and yahoo games

    hello everyone,
    i have a mac 10.6.8 with java SE 6 1.6.0_33-603-424 and i have problems with yahoo games.... anyone can help me please, i have a mac 10.6.8 with java SE 6 1.6.0_33-603-424 and i have problems with yahoo games.... anyone can help me please

    So here is what comes to pass.
    Recall this started as a Lion Safari/5+ environment that SU took to version 6.
    Two weeks ago I just updated Flash Player. Today I fire up Java Preferences and I am told that I need to download Java. Did so, intentionally hit the "factory reset" button and then installed the Flash Player from teh Adobe site. The most recent install suggests automatic update but I choose "ask first."
    Restart Safari and we seem to be in order
    Thanks

Maybe you are looking for

  • Are you sure you want to shut down your computer now?

    I keep getting the subject message when I start up the computer. The only way I can get rid of of the message is if I keep rebooting the system for a while. Any one have any ideas as to what is causing this??? Thanks Model Name: Mac Pro Model Identif

  • Photo Files and iPhoto Questions

    I have a few questions in relation to my actual picture files and when they are imported into iPhoto (on my mac). Intro: Let me catch you up on my situation, I have all my picture files (around 8000 of them!) on my time capsule; most of them are orga

  • Middle select button not working correctly?

    I have a nano second generation and the select button in the middle is not working correctly. I have to keep pushing it and pushing it to get it to work and now it's not working at all. Any ideas?

  • BAPI_InspectionPlan_Create-Create Operation based on First Operation

    Hi All, I am uploading inspection Plan using BAPI_Inspectionplan_create method.For This one operation had already been created.I need to create the next operations as a copy of first operation except for the change in operation description. Could som

  • Data (p6.2) Migration from one server to another server with  P6.7

    Dear All, pls help me by naming some reference material or procedure steps. I need to know this asap as I have got a date to perform this task. rgrds abhi