JAVA Unzipping XLSX

Discussion in 'Mac Programming' started by davidlt, Nov 27, 2009.

  1. davidlt macrumors member

    Joined:
    May 22, 2007
    Location:
    Lithuania
    #1
    Hello,

    I am trying to unzip XLSX file (yes, Excel) and to get to the data in XML files. The problems is that I cannot extract it.

    Here it is:
    Code:
    david-mac:oracle david$ java Unzip data.xlsx 
    Extracting file: [Content_Types].xml
    Extracting file: _rels/.rels
    Unhandled exception:
    java.io.FileNotFoundException: _rels/.rels (No such file or directory)
            at java.io.FileOutputStream.open(Native Method)
            at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
            at java.io.FileOutputStream.<init>(FileOutputStream.java:70)
            at Unzip.main(Unzip.java:123)
    If I launch that in Windows I get Access is Denied (message of Exception).

    And here is example code I am using:
     
  2. SydneyDev macrumors 6502

    Joined:
    Sep 15, 2008
    #2
    Perhaps if you also called mkdirs on the file entries. Based on the output you pasted, there was no _rels dir entry encountered before the file in the _rels dir.
     
  3. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #3
    If you just want to unzip the file, use the 'unzip' command:

    http://developer.apple.com/mac/library/DOCUMENTATION/Darwin/Reference/ManPages/man1/unzip.1.html


    The 'jar' command can also unzip it:
    Code:
    jar xf path/to/file.xlsx
    
    Or list the contents:
    Code:
    jar tf path/to/file.xlsx
    

    Finally, this is a faulty assumption:

    There is no requirement to store any entry for dirs. It is perfectly legal to just use /-delimited pathnames in the zip archive. Read the spec.
     

Share This Page