Problen in unzip a file in folder structure

hi,
how can i unzip a file and folder with folder structure. when i unzip a file it create problem. please help to solve this problem.
here is my code
import java.io.*;
import java.util.zip.*;
public class MakeUnzip {
final static int BUFFER = 2048;
public static void main (String argv[]) {
try {
BufferedOutputStream dest = null;
FileInputStream fis = new FileInputStream("D:/serverdata/dates.zip");
// String root = "D:/clientdata/";
ZipInputStream zis = new
ZipInputStream(new BufferedInputStream(fis));
ZipEntry entry;
ZipFile zipfile = new ZipFile("D:/serverdata/dates.zip");
while((entry = zis.getNextEntry()) != null) {
int count;
byte data[] = new byte[BUFFER];
if(entry.isDirectory()){
     File dir = new File(entry.getName());
     if(!dir.exists()){          dir.mkdir();                 }      
FileOutputStream fos =null;
fos = new FileOutputStream(entry.getName());
dest = new BufferedOutputStream(fos, BUFFER);
while ((count = zis.read(data, 0, BUFFER))
!= -1) {
dest.write(data, 0, count);
dest.flush();
dest.close();
zis.close();
} catch(Exception e) {
e.printStackTrace();
Please give me solution.
Thanks in advance

try this one and change it as u like:
import java.util.zip.ZipFile;
import java.util.zip.ZipEntry;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.io.File;
public class UnzipFile {
private static void doUnzipFiles(String zipFileName) {
try {
ZipFile zf = new ZipFile(zipFileName);
System.out.println("Archive: " + zipFileName);
// Enumerate each entry
for (Enumeration entries = zf.entries(); entries.hasMoreElements();) {
// Get the entry and its name
ZipEntry zipEntry = (ZipEntry)entries.nextElement();
if (zipEntry.isDirectory())
boolean success = (new File(zipEntry.getName())).mkdir();
else
String zipEntryName = zipEntry.getName();
System.out.println(" inflating: " + zipEntryName);
OutputStream out = new FileOutputStream(zipEntryName);
InputStream in = zf.getInputStream(zipEntry);
byte[] buf = new byte[1024];
int len;
while((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
// Close streams
out.close();
in.close();
} catch (IOException e) {
e.printStackTrace();
System.exit(1);
public static void main(String[] args) {
if (args.length != 1) {
System.err.println("Usage: java UnzipFile zipfilename");
} else {
doUnzipFiles(args[0]);
}

Similar Messages

  • Use Automator to move files and folder structure to another folder, retaining destination contents

    I have been struggling trying to setup Automator to move files and folder structure to another folder, retaining the destination contents.  Basically, I need to add files at the destination, within the same folder structure that exists at the source.  Here's some details about the scenario:
    -I have PDF files that I create on a seperate computer than I my daily use machine
    -For security reasons, the source computer doesn't have access to any shares on the destination computer
    -The destination computer has access to shares on the source computer
    -I want to delete the original PDFs at the source after they are moved or copied
    I haven't been able to get Automator to move or copy the folder contents (files and subfolders) without dropping everything copied at the top level of the destination, resulting in many duplicate folders and a broken folder structure.
    So far I've only had luck getting this to work at the command line, but I'd really like to have this setup in Automator so that I could have either a service or application that I could use for any folder, prompting for the source and destination folders.  I'm a relatively new Mac user with limited Linux experience, so this is the command that I've cobbled together and currently accomplishes what I'm looking for:
    ditto /Volumes/SMB_Temp/SOURCE ~/Desktop/Documents/DESTINATION
    cd /Volumes/SMB_Temp/SOURCE
    find . -type f -name "*.pdf" -exec rm -f {} \;
    Thanks for any ideas!

    If you have a command-line syntax that works, why not just create an Automator workflow with a single 'Utilities -> Run Shell Script' action, where that action has your (working) shell commands?
    Seems way, way simpler to me than trying to reinvent the wheel and transcribe shell commands into individual Automator actions

  • How to check In a file with folder structure

    Hi,
    Is it possible to check in "a file with its complete folder structure".
    For Ex: folder A contains Folder B and B contains a file , Then is there an option to check in the file in content server with the same structure A-->B-->file.
    Thanks In advance.

    JRS, this will copy ALL the files and folders from folder A to the content server.
    If he only wants to copy file A that is inside folder B than your way is somewhat overkill unless you are sure that the file is the only one in the complete structure but that i doubt...
    I haven't checked it before but perhaps someone can tell if this is possible...
    If you check in a file, perhpas you can get the original file and foldername from the metadata. If this is possible, you can create your own code that hooks on the check in and then create a directory or just move the file in the directory.
    I have written such a component but it's based on some custom metadata we use, not on the original filename.
    If i find the time, i will try some things and tell you if it works

  • Moving files and folder structures in PSE8

    I have a new computer with much more hard disk space.  So now I want to move about 2,000 photos in the organizer from an external hard drive to my local drive.  Easier to work with my photos that way, and I have automatic backup of my hard drive to an internet offsite storage.
    When I tried using the File->Move function, the files moved but not the underlying file structure.
    Yes, my photos are tagged in the organizer.  But I very much want to preserve the file structure, too.
    Is that possible?
    Jim, San Francisco

    Jim,
    You can move your folder structures from folder view in Organizer. Just drag the parent folder in left folder browser to the destination parent.
    Let me know if that works for you.
    Regards,
    vaishali

  • Custom application to upload entire folder structures into KM at once

    Does anyone know of a way (or has an idea of how) to create an application that could be put in an iView to allow the user to select a folder on his/her PC to be uploaded onto KM, subfolders and all?  I have found sample apps that let you upload single files into KM, but none for multiple files or folder structures.
    Thank you

    Hi,
    Some ideas..
    Maybe you should try zipping the whole folder and uploading it. The upload program should unzip the file using the zip APIs from Java, and move the folder into an File Sytem or FSDB repository.
    If you are using the CM repository of type DB then you will have to look at the IResource and ICollection creation APIs to build the folder structure and transfer content.
    Regards
    Pran

  • Unzip the file

    I need to Unzip a file from Folder 1 and place it in Folder2.
    Folder 1 has a zip file, which a txt file embedded in it. PI need to unzip the file and place the file in Folder2 with same name.
    I have created a Configuration Scenario for this, no IR objects.
    I have used PayloadZipBean with ModuleConfiguration as
    ParameterName- zipmode and ParamterValue - unzip in my sender file channel and same  is used in receiver channel.
    For some reason when I see the payload in sender communication channel log, it is automatically converted to XML with some junk values along with the data.
    Another issue is although I have checked the Adapter Specific Properties on both the channels, it expects a name on Receiver file channel. So I have given a dummy name there. File got created in Folder2 but with some junk values in XML format.
    Any thoughts please.

    Thank You both.
    Greg - your idea worked.
    On the other issue looks like I can not use Adapter Specific Properties on both the channels. when I use ASMA File got created in Folder2 but with some junk values in XML format.
    Looks like it expects a name on Receiver file channel. So I have given a dummy name there.
    Edited by: Vamsi on Feb 23, 2012 6:15 PM

  • Folder Structures

    Hello All,
    I was using iView Media Pro, until I picked up Aperture. Quick question ... since Aperture stores all photos in one library file, is there a way to get access to images from Photoshop without having to export from Aperture? Also, I am aware of showing package contents of the Aperture Library file, but this does not really do any good if I am attempting to locate a file in Photoshop.
    For the record, I like Aperture. I just hope there will eventually be an easier way to gain access to pictures from the Finder.

    This is a way to keep your existing file structure in aperture and then keep a separate set of smart folders which can relate to your existing file & folder system. Its not ideal & it doesn't show up in photoshop file browser but it works reasonably well.
    I run a picture library & need to keep track of approx. 70,000 images. These are in lots of file formats including .jpg .tif and raw files both camera specific eg. .NEF .CRW & also files from non-supported cameras converted into .dng files.
    I will use aperture as a management system to quickly look for & sort files. I would use it for some basic editing to make images for my website for example - but until it improves will need to use photoshop for raw conversion & serious editing.
    Since aperture uses its own library structure which is difficult to locate i need - as i'm sure many other people need - a simple way of quickly looking through my library to find files independent of aperture. This is a method i came up with. It does however require a fair amount of planning ahead as you have to import folders into aperture one by one and then create your smart folder. When you have done that you can move onto the next one.
    1) Decide on how you want to split up your existing library & make sure its organised.
    I run a library which specialises in travel images of France so its organised in this way.
    Main Regions of France>Sub-areas>images etc. So in real terms this works out as:
    ALPS(FOLDER)>grenoble(sub-folder)>cable-car1.jpg(image) I'll use this an example & you should be able to see how it works.
    2) Firstly in aperture I set up a new project called FRANCE LIBRARY.
    3) I then click on it & go to Import>Folders Into a project. In this case its a folder called ALPS.
    4) All the files & folders within the main folder ALPS then copy to aperture in the same structure as i've already got them organised.
    5) The next step is to find those images & set up a smart folder for all the different kinds of file types within it.
    6) Go to Finder>File>New Smart Folder
    7) Find your Aperture Library from the menu on the left - wherever you've stored it.
    8) Right click it (or cntrl + click) and click Show Package Contents
    9) There should be a project file file. In my case its called FRANCE LIBRARY.approject
    10) Right click it and click Show Package Contents
    11) You should then see a folder with an .apimportgroup extension.
    12) Open it & there are separate folders for each of the images. Each folder
    includes the actual image + the adjustment etc. files.
    13) In the spotlight search box ( top right hand corner) type a search criteria.
    use the extension for one of the files you've got in there. eg. jpg
    14) click on the + symbol (its below the search box to the right of Save)
    15) 2 boxes then appear on the left called Kind & Any
    16) click on Any & select Images
    17) delete whatever you entered in the search box. this is an important step
    as its stops the folder only displaying jpgs.
    18) The folder should then display thumbnails of all the images in that .apimportgroup folder. in my case this includes .jpg .tif .dng files.
    19) then click Save to name & save folder.
    20) It only lets you save in one of 3 places but you can always move it
    to where you want.
    21) You now have a folder of thumbnails - stored wherever you choose.
    22) If you right click the image you can then go to Open With & open it in whatever programme you choose. ie. photoshop.
    You can then go back to aperture and import the next batch - following all the steps again.
    You can obviously set up the folders how you want. You can choose to have lots of them or a few.
    I do this one at a time as its easy to spot the new .apimportgroup folder. If i imported my whole library at once i'd just have one huge folder - this way i can keep them organised as i want them & in a way i'm familiar with.
    This means that i can set up the same file and folder structure in aperture & within smart folders as i have in my existing library.
    Its complicated & its far from ideal but it works. Even though aperture stores files in its own library they are still visible (admittedly through a complicated procedure) even if aperture ceased to exist as a programme it would still be possible to see all the images in its library by using this method. You can then copy them - burn them to dvd - back them up on another disk - ie. do the same as files in a "normal" folder. As far as i know smart folders will update if you delete from or add to them
    As a way of integrating it into photoshop for converting raw files - its possible to have a smart folder containing raw files in place of photoshop bridge & then right click on the image you want to convert - click open with photoshop & the image will appear in the photoshop camera raw converter.
    Aperture has some really useful features & also some features that need to be improved asap. I've emailed apple 3 times so far so i'm not a fan of it yet.
    For my particular business its very useful in lots of ways - but it needs some work to be what many of us hoped it would be.
    ps. if there are any errors in this please let me know. i followed the procedure through as i was typing so i am hoping its all ok.
    G5   Mac OS X (10.4.3)  
    G5   Mac OS X (10.4.3)  
    G5   Mac OS X (10.4.3)  
    G5   Mac OS X (10.4.3)  
    G5   Mac OS X (10.4.3)  
    G5   Mac OS X (10.4.3)  
    G5   Mac OS X (10.4.3)  

  • LV8 Application Builder Folder Structure

    I have a folder structure in my development environment.
    When I build an application, using the application builder, I want to get the same folder structure.
    Example:
    I have folders ..Application\Drivers\DMM\Agilent 34401 and ..Application\Drivers\DMM\Fluke 45.
    There are subfolders containing VI:s in each folder (..Application\Drivers\DMM\Agilent 34401\Subs\sub.vi)
    In the application builder I add ..Application\Drivers to "Dynamic VIs and Support Files".
    I create a new "Destination".
    Now all vi:s from ..Application\Drivers goes to this folder, not to subfolders.
    Is it possible to get a folder structure?
    Staffan Ekstrom
    Sony Ericsson Mobile Communications AB
    Lund, Sweden

    Hi Staffan,
    When you build an application all of the VI:s will be integrated in an .exe file. The reason for this is that the user of your program not shall be able to do changes in the source code.
    When adding files to the "Dynamic VIs and Support Files" these files are for example help files that you want the program to find no matter where you install your program on the computer. Before adding files to this you need to build the relative path in the program using strip path.vi and build path.vi.
    Dynamic VI:s are not the same as sub VI:s.
    The short answer to your question is no, there is not possible to get a file and folder structure when building an application.
    Regards,
    Andreas E
    Applications Engineer
    National Instruments

  • Unzip a file preserving the folder structure

    Hi guys,
    I have create a zip file using java.util.zip and I preserv all directory structure. When I unzip the file using the same library, in the loop of ZipEntry I don't find never a directory. This the code that I use and don't work:
    public void dataDecompression(String pathArchivio) {
        try {
            fileInputStream = new FileInputStream(pathArchivio);
           checkedInputStream = new CheckedInputStream(fileInputStream, new Adler32());
           zipInputStream = new ZipInputStream(new BufferedInputStream(checkedInputStream));
           ZipEntry entry;
           while((entry = zipInputStream.getNextEntry()) != null){
                if(entry.isDirectory()){
                     //make dir          
               else{
                    //write file
    }Maybe I miss something in compression? Excuse for my bad english.
    Thanks in advance.

    three problems with that.
    1) you don't recusively create folders.
    2) you create a folder with the name of the file you want to write.
    3) you don't create files.
    File file=new File(entry.getName());
    if(file.getParentFile()!=null);
         file.getParentFile().mkdirs();
    if( !entry.isDirectory() ) {
    //code that write file;

  • 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.

  • How can I batch move files to the same folder structure in a different location?

    Hi,
    I recently had an issue with my iTunes Library so I used the Organize Library feature to have iTunes organise my library.  What happened was that it put all of my music in a folder called 'Music' on my external hard drive, whereas previously it was not in a folder at all, e.g.
    BEFORE: External Hard Drive / Abba / Greatest Hits / Mama Mia.m4a
    AFTER: External Hard Drive / Music / Abba / Greatest Hits / Mama Mia.m4a
    I don't have any particular issue with the updated folder structure, except that I had copies of the artwork for each album in my album folders, and these weren't moved when the audio files were moved/consolidated/organised.  So I need to find a way of moving all of the artwork to the new folders, e.g.
    External Hard Drive / Abba / Greatest Hits / folder.jpg
    needs to become:
    External Hard Drive / Music / Abba / Greatest Hits / folder.jpg
    I have to do this for 3,000+ albums, and I have multiple artwork files for some albums, so I am hoping that there is a way of doing this using a batch/automated method of some kind, but I haven't been able to turn up anything yet.
    Can someone help with this?
    Thanks,
    Nick

    You can make a smart playlist containing episodes of both series and play from that. Podcasts are linked together by the URL they are served from so merging ongoing series isn't really practical.
    tt2

  • How to make file folder structure from virtual folders

    lv 2013 sp1
    This is the layout of an example project, (please don't mind the horrible naming)
    When i create a source distribution.. no matter what settings I try, the preview is always like this:
    But I want the folder structure from the build to become as the virtual folder structure. is there any way of doing this without moving them by hand in the file explorer tab?
    Solved!
    Go to Solution.

    Unless you use auto-populating folders (which I don't like), the virtual folders are not meant to reflect the location on disk, so it certainly won't be automatic.
    I don't have experience with source distribution, but other build types have the option of configuring destination folders in the Destinations category and then assigning these destinations to items in the projects (including virtual folders, which then takes all the elements inside it) either in the same category or in the one under it, I can't check. I expect that you can do the same in a source distribution.
    Try to take over the world!

  • Transparent integration of a new drive into the folder structure of a file server?

    Hallo,
    I'm looking for solution to a problem, that seams to be simple, but obviously is not that easy to solve:
    I have to integrate a second external RAID system in to our MacOS X 10.6.8 Server based file sharing server that is accessed from Mac and Windows clients via AFP and SMB. I want to move one or two main folders from the old RAID to the new one, but this physical change has to be invisible to the users, as I don't want to confuse anyone.
    So my idea was to mover the Folders to the new drive, and create symbolic links at the old locations pointing to the new locations. This works very well for the Windows clients accessing the server via SMB, but does not work for the Macs on AFP.
    So I tried to move one folder to the new drive and mount it at the old location. Again this works fine for the SMB but does not work for AFP, the mount point does not show up in a directory listing via AFP.
    Do you have any other idea how I might integrate the new drive in transparent way into the old folder structure?
    Thanks for your input
    Florian
    PS: I could use SMB on the Macs but for some reason I, whenever I try to log into the server from a Mac via SMB, user name and password are accepted, but then the Mac client displays a message saying that I don't have the right to access the share. The same share works using AFP.

    Define 'invisible' please.
    Do you mean you need to be able to do this live, while users are on the system? or just that you can shut the machine down, reconfigure it, and bring it back up with the new configuration, even though the shares look the same to the users?
    I'm guessing the latter, but it's worth asking.
    Ultimately the problem lies in the way the file sharing systems deal with multi-volume sharepoints, and it's not easy. If you think about it, say you have a 1TB array handling the main sharepoint and you want to substitute one of the directories in that sharepoint with a new, empty 4TB array.
    When the user mounts the sharepoint they get a little status bar at the bottom of the window showing the available space... how much is that? Well, initially it would be however much of the 1TB volume is unused... except if they switch to the linked directory they now have 4TB available (or thereabouts)... so the amount of space available has changed even though, from the user's standpoint, they're still on the same share.
    It isn't valid for the OS to report 4 TB as free because that isn't the case unless you're in this specific directory.
    It also isn't valid for the OS to report 5TB free, even though there is that amount of space altogether.
    It also isn't valid for the OS to report 1TB free because you could upload 4TB of data if you put it in the right place.
    There are few solutions to this. Microsoft sort of addressed this with their DFS solution in Windows Server, but it's not trivial.
    Unfortunately you can't just blow it off and ignore the issue.
    Off hand there's only one thing I can think of that *might* work. if it doesn't then you're down to using multiple sharepoints on the server, with users mounting both disks simultaneously (which can be automated, for what it's worth).
    The one thing to try is to statically mount the second RAID at the appropriate location so that, as far as the OS is concerned, it looks like just another directory even though it's on a different disk. You'd do this by editing /etc/fstab and adding a line like
    UUID=AABBCCDD-79F7-33FF-BE85-41DFABE2E2BA /path/to/mount    hfs   rw
    to /etc/fstab (this file may not currently exist, so just create it as root).
    The first field is the UUID of the drive (which you can get via diskutil info)
    The second field is the path where you want this drive to appear in the filesystem - i.e. somewhere in the path of your sharepoint. There must be an existing (empty) directory at this path when the disk mounts.
    The third field identifies the disk as HFS
    The fourth field marks the disk as read-write
    Now when the system boots it should locate this disk and mount it on top of the existing RAID volume. If you cd to your sharepoint you should see the existing drive and if you cd from there into your mounted directory you should be looking at your new RAID.
    Now, this all works fine (or, at least, should do) from a standard OS standpoint. The big question is whether the AFP and SMB daemons honor and support this kind of setup... there's one way to try, of course...
    Now for testing purposes you could mount it at a dummy directory, just to see whether it's available to network clients. If it is then your next step would be to clone the data from the directory onto the new drive, then edit the fstab to mount the disk at the appropriate location.
    Note also that the entire volume will replace the directory you mount over - that means you can't replace two (or more) directories with one volume, but you can, of course, partition or setup your RAID into multiple volumes and mount each individual volume over a specific directory.

  • Building a war file with a folder structure

    How do a build a war file with a folder structure? I have code that creates JarEntrys and writes jar files and resource files etc. to the war. When I look at the war that gets created using winzip the path names for all the entries are correct and everything appears correct. When I try to deploy this to Tomcat nothing deploys. It appears my war is in a folder structure. How can a build this folder structure in the war? When I look at a good war using BeyondCompare I see folders and files in the folders just like I would see looking at a directory on my system. When I use BeyondCompare to view one of my "bad" war files that I have created everything is in the root. There are no folders and no folder structure. I am using the java.util.jar API to create the war but I don't see any methods or any API that will let me build up any sort of folder structure. It seems like I am missing something basic here.

    command is same for creating jar/war/ear.
    u simply need to execute jar /? for detail.

  • [svn:osmf:] 10584: Adding a missing file from that last folder structure refactor.

    Revision: 10584
    Author:   [email protected]
    Date:     2009-09-24 17:19:48 -0700 (Thu, 24 Sep 2009)
    Log Message:
    Adding a missing file from that last folder structure refactor.
    Added Paths:
        osmf/trunk/plugins/akamai/AkamaiBasicStreamingPlugin/AkamaiBasicStreamingPlugin.as

    Hello,
    Welcome to MSDN forum.
    I am afraid that the issue is out of support range of VS General Question forum which mainly discusses
    the usage of Visual Studio IDE such as WPF & SL designer, Visual Studio Guidance Automation Toolkit, Developer Documentation and Help System
    and Visual Studio Editor.
    Because your issue is about ASP.NET web application development, I suggest that you can consult your issue on ASP.NET forum:
    http://forums.asp.net/
     for better solution and support.
    Best regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

Maybe you are looking for