Urgent ! How to Zip Folder Contents including files and sub folders.

Hi, i need an urgent help from you regarding zipping the contents of any folder/directory including its sub folders and files to a .zip file. Please provide a code for ot or help me out. It is really very urgent.
Thanx Waiting....

This class can add a string or file to a ZIP. Maybe you can adapt it to do a directory and all its subfolders and files recursively:
package demo;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import java.util.zip.ZipException;
* Demo for using the Zip facilities to compress data
public class ZipDemo
    /** Default buffer size */
    private static final int DEFAULT_BUFFER_SIZE = 4096;
     * Compress a string
     * @param uncompressed string
     * @return byte array containing compressed data
     * @throws IOException if the deflation fails
    public static final byte [] compress(final String uncompressed) throws IOException
        ByteArrayOutputStream baos  = new ByteArrayOutputStream();
        GZIPOutputStream zos        = new GZIPOutputStream(baos);
        byte [] uncompressedBytes   = uncompressed.getBytes();
        zos.write(uncompressedBytes, 0, uncompressedBytes.length);
        zos.close();
        return baos.toByteArray();
     * Uncompress a previously compressed string;
     * this method is the inverse of the compress method.
     * @param byte array containing compressed data
     * @return uncompressed string
     * @throws IOException if the inflation fails
    public static final String uncompress(final byte [] compressed) throws IOException
        String uncompressed = "";
        try
            ByteArrayInputStream bais   = new ByteArrayInputStream(compressed);
            GZIPInputStream zis         = new GZIPInputStream(bais);
            ByteArrayOutputStream baos  = new ByteArrayOutputStream();
            int numBytesRead            = 0;
            byte [] tempBytes           = new byte[DEFAULT_BUFFER_SIZE];
            while ((numBytesRead = zis.read(tempBytes, 0, tempBytes.length)) != -1)
                baos.write(tempBytes, 0, numBytesRead);
            uncompressed = new String(baos.toByteArray());
        catch (ZipException e)
            e.printStackTrace(System.err);
        return uncompressed;
     * Uncompress a previously compressed string;
     * this method is the inverse of the compress method.
     * Implemented in terms of the byte array version.
     * @param string containing compressed data
     * @return uncompressed string
     * @throws IOException if the inflation fails
    public static final String uncompress(final String compressed) throws IOException
        return ZipDemo.uncompress(compressed.getBytes());
     * Main driver class for ZipDemo
     * @param command line arguments - either string or file name to compress
    public static void main(String [] args)
        try
            for (int i = 0; i < args.length; ++i)
                String uncompressed = "";
                File f              = new File(args);
if (f.exists())
BufferedReader br = new BufferedReader(new FileReader(f));
String line = "";
StringBuffer buffer = new StringBuffer();
while ((line = br.readLine()) != null)
buffer.append(line);
br.close();
uncompressed = buffer.toString();
else
uncompressed = args[i];
System.out.println("length before compression: " + uncompressed.length());
byte [] compressed = ZipDemo.compress(uncompressed);
System.out.println("length after compression : " + compressed.length);
String compressedAsString = new String(compressed);
System.out.println("length of compressed str : " + compressedAsString.length());
byte [] bytesFromCompressedAsString = compressedAsString.getBytes();
boolean isTheSameAs = bytesFromCompressedAsString.equals(compressed);
System.out.println("compressed bytes are " + (isTheSameAs ? "" : "not ") + "the same as from String");
System.out.println("length of bytesFrom...: " + bytesFromCompressedAsString.length);
String restored = ZipDemo.uncompress(compressed);
System.out.println("length after decompress : " + restored.length());
isTheSameAs = restored.equals(uncompressed);
System.out.println("original is " + (isTheSameAs ? "" : "not ") + "the same as the restored");
String restoredFromString = ZipDemo.uncompress(compressedAsString);
isTheSameAs = restoredFromString.equals(uncompressed);
System.out.println("original is " + (isTheSameAs ? "" : "not ") + "the same as the restored from string");
catch (Exception e)
e.printStackTrace(System.err);
MOD

Similar Messages

  • Deleting Files and (sub)folders - how to

    Hi,
    Easy question. Easy there a vbscript to delete all files and (sub)folders, empty or not. Important, here is that the parent folder must NOT be deleted, only it´s contents. (important: this folder is located on a mapped share \\servername\foldername\)
    please help

    Hi,
    ' Delete All Subfolders and Files in a Folder
    Const DeleteReadOnly = TRUE
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    objFSO.DeleteFile("C:\FSO\*"), DeleteReadOnly
    objFSO.DeleteFolder("C:\FSO\*"),DeleteReadOnly
    Save the above code in test file with .vbs file extension. modify "C:\FSO" to your folder.
    Disclaimer: This posting is provided AS-IS with no warranties or guarantees and confers no rights. Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually
    answer your question. This can be beneficial to other community members reading the thread.

  • Jsp code (js code) to display(tree) the files and sub folders in a folder

    Hi all
    plz can any one send me the source in jsp or js to display in tree structure for files and sub folders in a folder.

    There are dozens of Javascript tree widgets available on the Internet. Some are free. Some are good. Google will find them for you.
    (The only relevance of JSP to your question is that yes, you can generate HTML that uses one of those Javascript tree widgets.)

  • How can I move my address file and mail folders from one drive image to the active drive?

    I have a drive with recovered data from a crashed drive. How do I import the Thunderbird address file to the new, current drive ( also the mail folders ) ?

    Look at https://support.mozilla.org/en-US/kb/profiles-tb#w_how-to-find-your-profile to locate your profile on the recovered disk.
    If you are just starting TB with a new profile, the simplest thing to do would be to copy the recovered profile to the directory where your current profile is located. Then switch; see https://support.mozilla.org/en-US/kb/using-multiple-profiles to switch to the other profile
    If you have stuff in your current profile you need to save or merge, let me know and I will give you further instructions.

  • Apple loops for garageband pack doesn't show the folder content (loops, files...)  in ableton live suite 8 library browser, but I can see all the loops in the folder from finder. how can i fix this? help please.

    apple loops for garageband pack doesn't show the folder content (loops, files...)  in ableton live suite 8 library browser, but I can see all the loops in the folder from finder. how can i fix this? help please.

    Thanks Barney, I tried that but all that comes up in Spotlight are the log files that show the file paths! I don't know how Steam works. Are all the files held by Steam on their server perhaps?

  • How can I make a PDF file from each folders with layers, where each page is a each folder?

    How can I make a PDF file from each folders with layers, where each page is a each folder?

    I found an answer to my own question. A work around of sorts.
    Download Photoshop Elements 6 for Macintosh. With PSE6 I made a slide show with 550 images 1920x1200, without thumbs. I ran into one problem making the slide show. My images contained 4 images which had not ben created by Photoshop and could not be included in the slide show. Opening the images in Photoshop CS4 and re-saving them still did not make then acceptable. Not a big deal. I probably could have fixed the four images by stripping all EXIF data before opening them in Photoshop. BTW, PSE6 made the slide show in demo mode.
    I hope the bug in Photoshop CS4 will be fixed in Photoshop CS5.

  • How can I back up my files and photos on my iPhone to my iMac?

    How can I back up my files and photos on my iPhone to my iMac?

    You can back up the iPhone to your Mac with iTunes.
    Make sure, your iTunes version is up to date. Connect your iPhone to an USB port and launch iTunes.
    See this document: http://support.apple.com/kb/HT1766
    If you want a separate folder with your photos, download the camera roll contents by connecting the iPhone to USB. You emac will see it as camera and you can download the photos using Image Capture to a folder on your Mac, or using iPhoto or Aperture to your photo library.

  • Coping folder contents and sub folders

    So, I'm working on a little practice folder sync project (fun with my mac)...
    ...and I'v gotten hung up a bit because my little copying app doesn't seem to count folders and sub folders (which I suppose makes sense).
    My initial idea was to take just the date of modification and compare it to the last date that the app was run, inorder to only copy changed files. But this seems problematic on a few levels, so...
    So, my two part question is:
    1. Is there a simple command to copy folder contents and sub-folder contents, or do I need to tell the script to do each sub-folder individually?
    2. I imagine that a better way to manage which files/folders need to be updated is to create a file with a list of the contents, and dates of modification, and compare the new folder list and the old folder list to each-other... ok.. so, um. yeah. that sounds tricky.

    >1. Is there a simple command to copy folder contents and sub-folder contents, or do I need to tell the script to do each sub-folder individually?
    There are two common solutions to this.
    The first is to use the Finder's 'entire contents of...' command to get a list of everything in the folder, including sub-folders, the second is to make your script recursive - that is, it calls itself several times over.
    In the first case it's as simple as:
    tell application "Finder"
    set allItems to entire contents of folder "path:to:source:folder:"
    -- rest of code goes here
    end tell
    This can have problems, though, especially on very large directories since the Finder is not very efficient at building a list of hundreds or thousands of files.
    The recursive path is a little trickier, but you write a handler to process a folder then repeatedly call that handler, like:
    <pre class=command>on run
    set sourceFolder to (choose folder)
    processAFolder(sourceFolder)
    end run
    on processAFolder(theFolder)
    tell application "Finder"
    set allItems to items of folder theFolder as alias list
    repeat with eachItem in allItems
    if class of eachItem is folder then -- we have a subfolder
    processAFolder (eachItem)
    else
    -- code here to compare the file and back it up
    end if
    end repeat
    end tell
    end processAFolder</pre>
    So here you walk through the folder, each time you find a new folder, you walk through that until you're done. The code takes care of keeping track of where you are in the folder hierarchy.
    >2. I imagine that a better way to manage which files/folders need to be updated is to create a file with a list of the contents, and dates of modification, and compare the new folder list and the old folder list to each-other... ok.. so, um. yeah. that sounds tricky.
    There's no need to keep a file. Assuming you have two folders you can just walk through one of them checking to see if each item exists in the other, then copy the newer file to the other directory, like:
    <pre class=command>on processAFile(fileName, sourceDir, destDir)
    tell application "Finder"
    -- check if the files exist
    set sourceFileExists to (file fileName of folder sourceDir exists)
    set destFileExists to (file fileName of folder destDir exists)
    -- now comes the logic
    if sourceFileExists and not destFileExsits then
    duplicate file fileName of folder sourceDir to folder destDir
    else if destFileExists and not sourceFileExists then
    -- assuming you want a two-way synch
    duplicate file fileName of folder destDir to folder sourceDir
    else -- both files exist, so check mod dates
    if (modification date of file fileName of folder sourceDir) > (modification date of file fileName of folder destDir) then
    duplicate file fileName of folder sourceDir to folder destDir
    else if (modification date of file fileName of folder destDir) > (modification date of file fileName of folder sourceDir) then
    duplicate file fileName of folder sourceDir to folder destDir
    end if
    end if
    end tell
    end processAFile</pre>
    If you're not planning a two-way synch an even simpler option is to just keep track of the last time the synch was run. Then all you need to do on subsequent runs is ask the Finder for 'every file of folder sourceFolder whose modification date is greater than lastRunDate'.

  • TS4036 how can I view backed up files and delete things I don't need

    how do I view backed up files and delete thing I don't need

    You can't view individual files contained in the backup.  You can control which apps are backed up, and whether or not the camera roll is included in the backup, by going to Settings>iCloud>Storage & Backup>Manage Storage, tapping the name of your device under Backups, then looking under Backup Options.

  • How can i make shorten systemlog files and joblog files on OS

    Hello
    How can i make shorten systemlog files and joblog files on OS

    Hello Jan,
    You can limit the size of system log.
    The size of the application server's System Log is determined by the
    following SAP profile parameters. Once the current System Log reaches
    the maximum file size, it gets moved to the old_file and and a new
    System Log file gets created. The number of past days messages in the
    System Log depends on the amount/activity of System Log messages and the
    max file size. Once messages get rolled off the current and old files,
    they are no longer retrievable.
    rslg/local/file /usr/sap/<SID>/D*/log/SLOG<SYSNO>
    rslg/local/old_file /usr/sap/<SID>/D*/log/SLOGO<SYSNO>
    rslg/max_diskspace/local 1000000
    rslg/central/file /usr/sap/<SID>/SYS/global/SLOGJ
    rslg/central/old_file /usr/sap/<SID>/SYS/global/SLOGJO
    rslg/max_diskspace/central
    Refer to http://help.sap.com/saphelp_nw70/helpdata/EN/c7/69bcbaf36611d3a6510000e835363f/content.htm
    for explanation of profile parameters.you can reduce the size of system log using rslg/max_diskspace_local and rslg/max_diskspace_central
    But you can't reduce the size of job log files on OS
    Rohit

  • Can you help me find pix that I stupidly made a new folder in temp files and now can't find my pictures?

    Can you help me find pix that I stupidly made a new folder in temp files and now can't find my pictures?

    Mac Pro
    Using a MacBook Pro    
    Two different computers.  One is a desktop & the latter is a Notebook.  Which one are you having issues with? 
    Which os is installed on your computer?
    Please describe in detail all you have attempted to do in order to resolve the issue.  How did you "search?"

  • My computer crashed, how do I transfer all my files and apps to a new computer?

    Hi All,
    Please help! My computer crashed, how do I transfer all my files and apps on my iPad to my new computer?
    Thanks so much,
    Jeff

    '''Firefox''' is the name. ''Foxfire'' is a bio-luminescent fungus. <br />
    [http://en.wikipedia.org/wiki/Foxfire_(bioluminescence)]
    See this article for moving all your Firefox personal data to the new PC.<br />
    http://support.mozilla.com/en-US/kb/Recovering+important+data+from+an+old+profile

  • How can one  read a Excel File and Upload into Table using Pl/SQL Code.

    How can one read a Excel File and Upload into Table using Pl/SQL Code.
    1. Excel File is on My PC.
    2. And I want to write a Stored Procedure or Package to do that.
    3. DataBase is on Other Server. Client-Server Environment.
    4. I am Using Toad or PlSql developer tool.

    If you would like to create a package/procedure in order to solve this problem consider using the UTL_FILE in built package, here are a few steps to get you going:
    1. Get your DBA to create directory object in oracle using the following command:
    create directory TEST_DIR as ‘directory_path’;
    Note: This directory is on the server.
    2. Grant read,write on directory directory_object_name to username;
    You can find out the directory_object_name value from dba_directories view if you are using the system user account.
    3. Logon as the user as mentioned above.
    Sample code read plain text file code, you can modify this code to suit your need (i.e. read a csv file)
    function getData(p_filename in varchar2,
    p_filepath in varchar2
    ) RETURN VARCHAR2 is
    input_file utl_file.file_type;
    --declare a buffer to read text data
    input_buffer varchar2(4000);
    begin
    --using the UTL_FILE in built package
    input_file := utl_file.fopen(p_filepath, p_filename, 'R');
    utl_file.get_line(input_file, input_buffer);
    --debug
    --dbms_output.put_line(input_buffer);
    utl_file.fclose(input_file);
    --return data
    return input_buffer;
    end;
    Hope this helps.

  • How can i password protect some files and web sites?

    How can I possword protect some files and web sites on my mac air so others using my laptop can't access them?

    Set a password for your user; create other user accounts for when other people want to use it. You can create a "guest" login which gets wiped after every logout, if that's more appropriate for them.
    Matt

  • How do I record a sound file and send it as an attachment using my 4s?

    How do I record a sound file and send it as an attachment using my 4s?

    Hi,
    The following is the program[Click Here| http://saptechnical .com/Tips/ABAP/email/EmailProgram.txt] which will send any format file. Actual Creator of the program is Amit Bisht.
    Thanks & Regards,
    Rock.

Maybe you are looking for

  • Import format and/or digital copy protection issues

    I'm new to the iTunes thing recently purchasing two 3gs iPhones. I have several hundred CD's ripped to FLAC format on a NAS device. When I add the networked folder to my iTunes it seems to read the directory and then add nothing to the library. I hav

  • Get Security Associated to a Report

    Hi, I'm trying to get the list of users/groups and their respective roles associated to a report. I already went through the ReportingServices2010 API and so far no method (Including GetPermissions) have returned this information. Is there a way to g

  • 6021 and synchronising contact with a company name

    Hello, does anybody know if it is possible to synchronise contacts with no pre name but only a company name? I can only get the names and extra info of these contacts on my 6021 but no company name. For the 6600 there is a seperate PC suite that can

  • Upgrade after 2 years

    Hi all, I just managed to do a complete upgrade (pacman -Syu) of Arch on my old laptop (which I seldom use). It went pretty smoothly, given that the last such upgrade was about 26 months ago! There were some problems, of course, and I had to use the

  • PS_PSP_PNR vs. MAT_PSPNR in MSEG

    Hello experts, I have been making some tests and it seems that it is possible to control the project stock in one WBS element (MAT_PSPNR) and control the costs in other WBS element (PS_PSP_PSPNR). Is that correct? I mean that I'm controlling the MRP