UnZipping an archive with folders inside

Hello, everyone.
A friend of mine asked me to create him an "auto-downloader" type of program, to download a ZIP archive, then extract the information to the user's computer (no, it is not harmful).
Anyways, I've been trying mutliple ways, and I've come pretty far with the one I'm currently using. The only problem is, I'm using user.home as the file location for the zip, and creating a folder in there seems to just not want to work. This is the only way I could think of doing it, but I'm sure there are easier ways.. here's what I'm using:
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import javax.swing.JFrame;
import javax.swing.JProgressBar;
public class Updater extends Thread {
     private String name;
     public void get(String url, String fileName) {
          name = fileName;
          JFrame frame = new JFrame(name.replaceAll(".zip", "") + " update");
          frame.setLocationRelativeTo(null);
          frame.setLayout(new BorderLayout());
          frame.setPreferredSize(new Dimension(500, 80));
          frame.setResizable(false);
          frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
          Client client = new Client();
          ClassLoader cl = getClass().getClassLoader();
          try {
               URLConnection connection = (new URL(url)).openConnection();
               String f[] = url.split("/");
               File file = new File(f[f.length - 1]);
               int length = connection.getContentLength();
               InputStream instream = connection.getInputStream();
               try {
                    new File(updatedDirectory()).mkdir();
               } catch (Exception e) {
                    e.printStackTrace();
               FileOutputStream outstream = new FileOutputStream(updatedDirectory() + file);
               int size = 0;
               int copy = 0;
               JProgressBar bar = new JProgressBar();
               bar.setStringPainted(true);
               bar.setMaximum(length);
               frame.add(bar, "Center");
               frame.pack();
               frame.setVisible(true);
               while ((copy = instream.read()) != -1) {
                    outstream.write(copy);
                    size++;
                    int percentage = (int) (((double) size / (double) length) * 100D);
                    bar.setValue(size);
                    bar.setString("Updating your " + name.replaceAll(".zip", "") + " - " + percentage + "% complete");
               if (length != size) {
                    instream.close();
                    outstream.close();
               } else {
                    instream.close();
                    outstream.close();
                    unzip();
                    //System.exit(0);
                    frame.setVisible(false);
          } catch (Exception e) {
               System.err.println("Error connecting to update server.");
               e.printStackTrace();
     private void unzip() {
          try {
               System.out.println(updatedDirectory() + "animations\\raw");
               InputStream in = new BufferedInputStream(new FileInputStream(updatedDirectory() + name));
               ZipInputStream zin = new ZipInputStream(in);
               ZipEntry e;
               //new File(updatedDirectory() + name.replaceAll(".zip", "")).mkdir();
               if (!new File(updatedDirectory() + "animations\\raw").exists()) {
                    if (new File(updatedDirectory() + "animations\\raw").mkdir()) {
                         System.out.println("worked");
                    } else {
                         System.out.println("nope");
               while ((e = zin.getNextEntry()) != null) {
                    unzip(zin, updatedDirectory() + e.getName());
               zin.close();
          } catch (Exception e) {
               e.printStackTrace();
     private void unzip(ZipInputStream zin, String s) throws IOException {
          FileOutputStream out = new FileOutputStream(s);
          byte[] b = new byte[1024];
          int len = 0;
          while ((len = zin.read(b)) != -1) {
               out.write(b, 0, len);
          out.close();
     public final String updatedDirectory() {
          //File file = new File(System.getProperty("user.home") + "\\info\\");
          File file = new File("..\\");
          if (file.exists() || file.mkdir()) {
               //return System.getProperty("user.home") + "\\info\\";
               return "..\\";
          return null;
}Here's the ZIP archive I'm trying to download: http://www.2shared.com/file/Qu1cSWcl/cache.html
If what I've said before doesn't make sense (mind you me, it's 4 am and I'm about to crawl into bed), then I'll try to sum it up in a few short words below.
I'm trying to extract a ZIP archive with folders, every time I do, it stops halfway through and throws an error similar to this:
invalid cache index specified
..\animations\raw
java.io.FileNotFoundException: ..\animations\raw (The system cannot find the pat
h specified)
        at java.io.FileOutputStream.open(Native Method)
        at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
        at java.io.FileOutputStream.<init>(FileOutputStream.java:70)
        at Updater.unzip(Updater.java:99)
        at Updater.unzip(Updater.java:90)
        at Updater.get(Updater.java:64)
        at Client.main(Client.java:2548)
Press any key to continue . . .I'm just trying to be able to extract cache (ZIP ARCHIVE) which has folders inside. I've tried creating a directory for the folder, but it seems to not work, hence the "?" in the above error (i printed that if the directory failed to create a new directory, as seen in my above code). Once again, sorry if this isn't as understandable as it should be, I'm not myself without sleep :)
Also, do ignore the first print, 'invalid cache index specified', it's not related to the problem.
Edited by: aeternaly on Jul 2, 2010 4:04 AM

So your question is really about how to make a directory, then. Nothing at all to do with unzipping of archives.
If you can't create a directory, then perhaps there is some permissions problem. You don't have the authority to create directories in some directory. Or perhaps you're trying to use a name which isn't a valid directory name in your system. Or... there are many other possibilities. But anyway I recommend tossing all of that unzipping business out of your program and just trying to write something which creates a directory. Debug that first.

Similar Messages

  • Archive unzips in windows with temp files

    Hello everyone. I am completely baffled. I had a folder of some photobooth pictures I was sending to my wife on her PC laptop. I used the Finder Make Archive utility, then Services to send the file through Mail.app. When she opened them on her end it looks like my entire internet cache was sent with it as well as other pictures from the original folder. When I open the .zip archive on my mac it just shows the 8 pictures I sent to her. Any ideas?
    Thanks

    The possibility that personal information on a person's drive could inadvertently be included in archives created using a "Finder" feature and sent out is a little disturbing. The issue of the inclusion of lists of folder contents contained in ".DS_Store" files eg. burned on to CDs has come up, but I haven't heard of actual files being included.
    But before jumping to any conclusions, it would be important to determine whether the archive process is the problem, or if the items were already there (i.e. if something else is creating hidden folders inside your original folder), and the "Finder" is just archiving what is there normally. Files hidden from the user in the "Finder" being visible to Windows users isn't that unusual.
    For example, if the original folder is still around, try launching "/Applications" > "AppleScript" > "Script Editor.app", entering the line "choose file" and hit "Run". A dummy dialogue box should open in "Finder", allowing you to navigate to the folder of interest, where its contents should be displayed, including invisible items.

  • I have a folder with 10 folders inside it, 8 of the folders will not function when I use "show view options".

    I have a Folder with 10 Folders inside it, 8 of the Folders will not function when I use "show view options", they always default back the default.  The "show view options" works on all my other Folders in my system, even on the first two of the Folder in question.  How can I correct it?  I have tried every thing I can think of, even deleting the Folders & reintalling them.  For some strange reason the "show view options" only does not work on the last 8 Folders in the Folder in question.

    Instead GarageBand recognize my keyboard and i can play normally, also, if it can help, those are the Audio and Midi Logic Preferences and the Controller Surfaces Setup with the keyboard connected :

  • How do I restore my archived mail folders after downloading Yosemite

    After downloading Yosemite, all my archived mail folders have disappeared - can someone please help me, I really need to get this information back?

    Do you have a backup?
    Go to Finder and select your user/home folder. With that Finder window as the front window, either select Finder/View/Show View options or go command - J.  When the View options opens, check ’Show Library Folder’. That should make your user library folder visible in your user/home folder.  Select Library. Then Mail/V2/Mailboxes

  • Unzipping the archive doesn't work

    Hi all,
    I just downloaded both windows versions of the new release of the program but when I try to unzip the archive it gives an error.
    I tried with winrar, zipgenius and zipcentral but none of them are able to unzip it.
    Any idea how to resolve this?
    Thanks

    That would be a CRC error. I'd say: download again, since mine (and everybody else's) works correctly. However you say you got the same problem with the one that has the JDK included... is the extraction failing on the same file? If so, maybe someone at Oracle is fondling with the files? If not, I'd say you got really bad luck or a really bad Internet connection (so keep trying until you get it right).
    K.

  • Folders inside a share are randomly disappearing

    Hello,
    I am having a strange problem with folders randomly disappearing off my server share. Here is my current setup:
    XServe running 10.4 connected to 3.5 TB Raid Array via Fiber
    Folder inside RAID shared out for client access via AFP and SMB
    All clients have automount setup in netinfo.
    Clients work fine for about a week, then folders start randomly disappearing. Not files so far, only entire folders. If we try and recreate the folder, it says that the folder already exists, but no one can see it, even if I log in to the server console and access the folders directly on the raid.
    I am not very mac savvy, so I am a bit lost as to what I should do next. This would be easier to diagnose if the whole share would become inaccessible, not just pieces.
    Anyone have any suggestions?

    We just started experience disappearing files. Running Server 10.4.11 (build 8S169). It happens with Autocad files when running Autocad on Parallels. I've been having flaky permission problems on the server, so I am thinking it's time for a (sigh) re-install of the server software.

  • I placed a personal folder in the sidebar of the finder. It had NB folders inside. This sidebar folder accidentally got dragged and went "poof" into a cloud of smoke. I cannot find the folder or it's NB contents anywhere. Help years of work!

    Hi,
    I need your help Please, I fear I might have lost years worth of work. 
    I had created 3 personal folders In my Home folder.
    I then created a new folder called "active folder" and dragged these 3 folders inside, removing them from the Home folder.
    I then dragged my newly created folder "Active Folder" to the Sidebar of the finder.
    When I had closed finder and reopened it - the "active Folder" folder was unable to open.
    A friend tried to help- dragged "active folder" off the sidebar.. and it disappeared with a cloud effect.
    I cant find that folder or its NB contents anywhere,
    Please help me with some advice if you can.
    Not using tiger or Lion.*

    When you created that "active folder," where did you create it?  And after you added it to the sidebar, what did you do with it?  If the data is truly nowhere to be found on your system, even using EasyFind, then I suspect you mistakenly deleted it, thinking that you had copied it to the sidebar.  That would explain why you later found that the "active folder" was unable to open from the sidebar.  The sidebar is just another way to access the original item, and if you deleted the original item, it can't do its job.
    Unfortunately, if this is what you did and you don't have any backups, you may be out of luck.  I don't know what you mean by saying you "did the whole data recovery 1's and 0's," but if you haven't already done so, you should try some dedicated data recovery software, to see if those deleted files may still be on the drive.  See Recovering deleted files.
    Ultimately, this is not a flaw in the Mac system, it is a flaw in your use of it.  I strongly recommend some reading to get up to speed:
    http://www.apple.com/support/mac101/
    http://www.amazon.com/Mac-OS-Lion-For-Dummies/dp/111802205X/
    http://www.reedcorner.net/guides/backups/
    http://www.takecontrolbooks.com/backing-up

  • Looking for a voice memo app with folders

    Looking for a voice memo app with folders
    I'm trying to find a simple voice memos app that allows me to save the voice memos in folders right on the phone, and have them backed up to my desktop when I sync. I used to use Recorder Pro by Bear-Software but it doesn't work properly anymore. It was great when it worked. Why do so many of the voice memo apps just keep your voice memos in one huge long unorganized list? I need to be able to create 10 or 15 folders within the app, and save each voice memo to a specific folder. Any voice memo apps come to mind?

    received this repsposne from the folks at Imesart:
    Dear Andrew,
    No app on iOS will let you add files to the music library. The only way to do this is to use iTunes on a computer.
    Regards,
    The Imesart Team

  • Put folders inside folders in iOS 7.1?

    Before I start, I'll just say that I have an iPad fourth generation.
    In the versions of iOS 7 before the recent 7.1, you were able to put folders inside folders on the home screen. I was wondering if there was a new way to do this.
    Maybe it was removed because it was a bug or glitch, but I am one of those type of people that like to have a ton of folders and have folders inside of folders because is my way of being organized. I really want to have the ability to do this again because it was one of my favorite things about iOS 7. After the update to version 7.1 I was happy about most other things about the update, but the fact that I couldn't put folders in folders anymore wasn't a particularly good improvement for me.

    I know I found it very annoying but hopefully they can have another update really soon so we can put a folder in another folder. Or hopefully the bug or glitch comes back :)

  • I'm trying to organize my movies with folders.  When I click "new folder", it either doesn't add any folder or adds a new folder as a "subfolder" of an existing folder.  Help!

    I'm trying to organize my movies with folders.  When I click "new folder", it either doesn't add any folder or adds a new folder as a "subfolder" of an existing folder.  Help!

    Thank you for the suggestion - I tried it but still didn't work.  When I click "New Folder" it gives me the pop-up to name the new folder, but doesn't put a new folder anywhere in my Project Library.

  • HT4061 good morning! I just did a software update on my phone (finally) last night and now my phone will not come on.  All it keeps showing is the charger pointing up to a blue circle with iTunes inside and will not go any further.  Can ANYone please expl

    Good Morning,
    I just did a software update on my phone (finally) last night and now my phone will not come on.  It keeps showing the charger pointing up to a blue circle with iTunes inside and will not go any further.  Can ANYONE help me please???

    The phone is in restore mode and the picture is telling you what to do. Connect the phone, by cable, to iTunes in the computer you normally use for syncing, and retore the phone.

  • Can't open iDVD 4 archive with iDVD 6.03

    I am trying to open a project created in iDVD 4 with iDVD 6.03. I saved it as an archive and transferred it from my emac to my macbook pro. The file is 76 mb so I believe the photos and theme is saved in the archive. When I try to open the iDVD 4 archive with iDVD 6 it either crashes immediately or does nothing. By doing nothing I mean that the archive does not open and the menus are still available in iDVD 6. Any suggestions would be appreciated.

    Don't ask me how I figured this out because it was really just dumb luck. The problem seems to be that the font I used on the emac and iDVD 4 was not on the macbook pro with iDVD 6. Once I dragged the font across the network it opened up fine. Too bad iDVD 6 couldn't give me an error message telling me that there was a missing font like some other programs do...

  • How do I lock an archive with a code?

    How do I lock an archive with a code?

    You can't. All you can do is create an encrypted disk image, mount it, and copy the archive to it.

  • Playlists with folders - doesn't work

    Brandnew iPod 30 GB, 5.5
    Do have playlists with folders on iTunes 7.0.2. Folders don't appear on the iPod. Only the files in the folders. So i get a long long list of playlists on the iPod. Instead of a list with several folders in it for better overview.
    Any hints? Thank you.
    PowerBook G4   Mac OS X (10.3.9)  

    But why?
    You could do it in the past.
    Software bug? Will there be a fix in the future?
    PowerBook G4 Mac OS X (10.3.9)

  • I can't export my video which contains only photos, sound tracks nor play it in fullscreen iMovie it shuts down. And now my whole file won't open at all it'll open with nothing inside ??

    I can't export my video which contains only photos, sound tracks nor play it in fullscreen iMovie it shuts down. And now my whole file won't open at all it'll open with nothing inside ??

    I also have Jolly's problem. I found the iMovie 9.0.9 folder and tried to launch the older version of iMove. It would not launch. I removed all of the iMovie preferences from the Preferences folder, removed iMove 10 from the applications folder, and restarted my Mac. iMove 9.0.9 still won't launch and I can't access my videos created with the older version of iMovie. Is there a way to uninstall iMovie 10 and reinstall iMovie 9.0.9?
    I am running Yosemitie on a  iMac.
    Paul

Maybe you are looking for

  • Crystal Report can't access db in enterprise XI

    Post Author: rgarabedian CA Forum: Administration Product:                    Business Objects EnterpriseVersion:                      XIPatches Applied:        SP3Operating System(s): Red Hat Linux Enterprise 4Database(s):                  PostgreSQ

  • How do I install a samsung clp-315 printer under Lion?

    I have upgraded to Lion. This morning I uninstalled my Samsung CLP-315 printer (I was trouble shooting & thought it would be easy to re-install). When I try to re- install via the system preferences my computer recognises the printer is there and tri

  • Environmentally friendly - shutting down or sleeping?

    Hi there, just wondering if anyone knows which is best in terms of being energy efficient and environmentally friendly? I am a student and use my powerbook intermittently throughout the day - I always wonder whether to shut down or just sleep my lapt

  • 10.5.8, External USB Modem, and Receiving Faxes

    Hello, I bought a Zoom external usb modem today, and am attempting to set up my computer to receive faxes on it. I followed the instructions that came with the unit and was able to send faxes. But when a call comes in, the computer doesn't pick up th

  • Old ical with new cloud

    I am using iCloud and Lion on all systems except 1, my office machine. I can't get the calendars on that machine to sync with iCloud. Any hints or tips please.