Unzip files from a folder which is updating regularly using multithreading

Hi All,
I have acode which unzip all the files from a folder .This code picks up all the zipped files at a time and then unzip it and write them to another folder but now my requirement is changed ,suppose the source folder where all the zipped files are present is refreshed or updated with new zipped files regularly then how can I implement in my code multithreading to get several files by threads and send it for unzipping.
Please suggest with some example or edit my code.
package com.myprojcet;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class Main {
     * Extracts a zip file
     public void extractZipFile() {
          try {
               String zipFileName = "C:\\soft\\test"; //Source folder for zipped files
               //Create input and output streams
               File SourceDir = new File(zipFileName);
               File[] zipFiles = SourceDir.listFiles();
               ZipInputStream inStream = null;
               OutputStream outStream = null;
               ZipEntry entry;
               byte[] buffer = new byte[1024];
               int nrBytesRead;
               //Get next zip entry and start reading data
          for(int i=0; i < zipFiles.length; i++) {
               inStream= new ZipInputStream(new FileInputStream(zipFiles));
               while((entry = inStream.getNextEntry()) != null) {
                    outStream=new FileOutputStream("C:\\soft\\test2\\"+entry.toString()); //destination folder for unzipped file
                    while ((nrBytesRead = inStream.read(buffer)) > 0) {     
                         outStream.write(buffer, 0, nrBytesRead);
               //Finish off by closing the streams
               outStream.close();
               inStream.close();
          } catch (IOException ex) {
               ex.printStackTrace();
     * @param args the command line arguments
     public static void main(String[] args) {
          new Main().extractZipFile();
Thanks
Sumit
Edited by: user8687839 on Feb 27, 2012 11:00 PM

But my question is that if in a source folder we have several files which are in zipped format and the folder is getting updated every min (say) with new zipped files (which are dumped from some outside environment).I need to unzip all the files present in the folder ,if new one comes there then also check for the new zipped file and unzip it.You don't need to keep re-stating that.
I had written a code for unzipping a file from a folder (thinking the folder is not updated everytime).Or that.
Now I am thinking of using threads because if I create suppose 5 threads and every threads poll the source folder and pick up a zip file ,send it for unzipping it and again poll the source folder for any new entries?Or that.
If using the threads here hits performace then what should I use?Err, what you presently have?
Provide me any sample code or link that would be more useful.You've already written it.

Similar Messages

  • We have an applescript that will batch print InDesign CS6 files from a folder to a laser printer using an InDesign print preset. The script does not work in OS X Yosemite. The script errors out with the print preset. Any thoughts?

    tell application "Finder"
      activate
      set thefolder to choose folder with prompt "Select a Folder with InDesign Files to be Printed" as text
      set thePath to thefolder as text
      set the selected_items to every item of folder thefolder
      if the selected_items is {} then
      beep
      display dialog "Please select a folder with InDesign files before running this script." buttons {"Cancel"} default button 1
      end if
      repeat with aFile in selected_items
      tell application "Adobe InDesign CS6"
      activate
      with timeout of 600 seconds
      set user interaction level of script preferences to never interact
      open aFile
      tell document 1
      tell print preferences
      set active printer preset to "Catalog Pages"
      set page range to all pages
      end tell
      print without print dialog
      close saving no
      end tell
      end timeout
      --might need this delay
      --delay 10
      set user interaction level of script preferences to interact with all
      end tell
      end repeat
      tell application "Finder"
      activate
      display dialog "Batch Printing is complete!" giving up after 5
      end tell
    end tell

    Hi
    After I put a small delay in as shown, your code ran fine, tested on about twenty ID files, using ID CC 2014, OSX 10.10.2
    tell document 1
    delay 0.5   -- delay added
      tell print preferences
      set active printer preset to "Catalog Pages"

  • I want to make a schedular which read xml files from a folder ,import in Indesign template then export as a pdf....

    i want to make a schedular probably in Coldfusion or using javascript ,  which read xml files from a folder ,import in Indesign template then export as a pdf....

    I don't think you understand: I want to open Dreamweaver and build a brand new site, then when I am done I want to host the dreamweaver site on the Business Catalyst platform. I dont want to use anything in BC to build the site, I just want to use the hosting platform. I do not want to import a BC site into dreamweaver or anything like that. I just want to use BC the same way I would use godaddy, or uhost or any other hosting provider. Based on your response you said that "of course its possible to build a BC site in Dreamweaver" I dont want to build a BC site, I want to build a Dreamweaver site and host it on the BC platform. Like I said before it doesnt seem like this is possible. As of now we can only build a new site in MUSE and integrate it into BC without using a BC template. Can you understand what I am saying. I DONT WANT TO USE A BC TEMPLATE, I WANT NOTHING TO DO WITH BC WHILE I AM BUILDING THE SITE WITH DREAMWEAVER, JUST LIKE MUSE DOES.

  • Unzip files from SDCARD

    HI,
    i am trying to unzipping files from external sdcard..
    i am using zipme.jar, but when i am deploying this application it give error.
    please nay one hep me to unzipping files using 3rd-party jar

    But my question is that if in a source folder we have several files which are in zipped format and the folder is getting updated every min (say) with new zipped files (which are dumped from some outside environment).I need to unzip all the files present in the folder ,if new one comes there then also check for the new zipped file and unzip it.You don't need to keep re-stating that.
    I had written a code for unzipping a file from a folder (thinking the folder is not updated everytime).Or that.
    Now I am thinking of using threads because if I create suppose 5 threads and every threads poll the source folder and pick up a zip file ,send it for unzipping it and again poll the source folder for any new entries?Or that.
    If using the threads here hits performace then what should I use?Err, what you presently have?
    Provide me any sample code or link that would be more useful.You've already written it.

  • Removed some files from library folder

    moved files from library folder and attempted to put them back after experiencing major changes and problem. This is not correcting the situation what can be done to restore it back to what it was before I started?

    Hi Ali,
    Update, I did a verify permissions with disk utility and some stuff is where it should be now, (recovered iphoto yeah) but still a problem with other things as before.
    So to answer your questions,
    What is the exact path to this folder? And please post the contents of the folder.
    I get to her old itunes by the following path;
    home>music>itunes>itunes music - this folder contains folder icons of all her old itunes library, each artist has a folder, such as amy cook>list of albums>list of songs - if selected will than open itunes and will import to new itunes library.
    I don't quite understand the heirarchy you are describing. Please post the contents of her Home folder.
    Her home folder contains
    Desktop
    Documents
    Library
    Movies
    Music
    Pictures
    plus 9 folders she had created over the past four years these are intact and accessible to proper application programs (ie documents open in appleworks, pictures are from the pictures library not iphoto, 3rd party software such as genealogy programs are intact and up to date)
    "I find some old unchanged items such as itunes, imovie, email mailbox items, in a folder that she created before the change took place in her user
    account."
    What is the exact path to this folder?
    As for this folder some things were moved back to proper places with the above mentioned verify permissions, some like, mailbox items, I was able to import to current settings to restore to how it use to be. From what I gather she created this file when things were going wrong and she feared messing the whole thing up. I access this by the following path;
    home>library>(then the folder she created) Library do not touch.
    When I compare the main library file to my account main library file they do not contain the same items in fact many of the missing items seem to be in this folder that she created. I assume the ones I need are in this file she created but I am really hesitant to just start moving things around out of fear of creating more problems on her side or messing up my side.
    If you have sufficient available disk space, you shouldn't have any problem, but you need a reliable backup, just in case.
    In regards to archive/install - sufficient available disk space meaning as much or more than what I am currently using? How do I check this to be sure?
    Which brings me to a whole new question if you have time?
    We do have an external back up system, which we used before a semi-recent move, (I plan on finding the box it is packed in believe me), however we attempted to use imacs backup program to do a quicker backup, were able to back up her side onto disks, but when I attempted to do the same on my side I received an failure error screen something about a drained buffer and being unable to perform a backup. Please tell me I have not fried my dvd drive!!!
    Thanks again, hope I answered in a way that is helpful to you.
    need to know

  • How to Copy an Image File from a Folder to another Folder

    i face the problem of copying an image file from a folder to another folder by coding. i not really know which method to use so i need some reference about it. hope to get reply soon, thx :)

    Try this code. Make an object of this class and call
    copyTo method.
    import java.io.*;
    import java.net.*;
    import java.util.*;
    public class FileUtil
    extends File {
    public FileUtil(String pathname) throws
    NullPointerException {
    super(pathname);
    public void copyTo(File dest) throws Exception {
    File parent = dest.getParentFile();
    parent.mkdirs();
    FileInputStream in = new FileInputStream(this); //
    Open the source file
    FileOutputStream out = new FileOutputStream(dest); //
    Open the destination file
    byte[] buffer = new byte[4096]; // Create an input
    buffer
    int bytes_read;
    while ( (bytes_read = in.read(buffer)) != -1) { //
    Keep reading until the end
    out.write(buffer, 0, bytes_read);
    in.close(); // Close the file
    out.close(); // Close the file
    This is poor object-oriented design. Use derivation only when you have to override methods -- this is just
    a static utility method hiding here.

  • Move files from one folder to another

    I am brand new to the application and have spent a ton of time googling various topics, but need some additional help. Seems easy enough, but I can't figure out how to do it...
    I would like to move pics from one folder to another. I can drag files from one folder to another, but they still reside in the original folder as well. Is there a way to cut and paste or a similar function to accomplish this move?
    Thanks.

    Hey, HawaiianHaole, as a multidecade Mac user, let me tell you, Aperture is about the worst example of Mac-iness one could imagine. Ironic, as it's (of course) made by Apple. But it is so inflexible, and insists so vociferously on making the user learn its peculiar interface conventions it reminds me most of something out of that famous company in Redmond.
    Want your Projects in an order you choose? Sorry! Want to arrange your windows so you can see your list of chat buddies while you're working in Aperture? Nope, can't do it! Aging eyes have trouble reading tiny grey type on a grey background? Hey buddy, it was your choice to grow old, don't blame us!
    But all is not lost. Aperture has gotten considerably better of late (versions up to 2.0 were fundamentally unusable in many ways) and will hopefully continue to improve. (ie Maybe they'll fix the printing thing...)
    Please don't make Aperture the basis for your judgement of the Mac OS. Many long time Mac users are having as much trouble with Aperture as you. Mac OSX has significantly reduced customizability but at the benefit of much improved stability and indeed usability. Old school Mac users had to learn to accept this, which most did. You'll hear people talk about the "Way of the Steve". As irksome as Aperture can be, you'll actually have a better time of it if you adopt the Way of the Steve, and accept that you can't do things the way you might want to. This is imho antithetical to the original Mac many of us knew and loved, but it's the way things are today, so we mostly shut up and take it. You can fight with your software all day, or just accept that there are ways you have to adopt and adapt to them.
    Welcome to the Bright Side, hope your Mac experience improves.

  • How to move files from one folder to another folder in webdynpro java for sap portal

    Dear Experts,
    I wan to move files from one folder to another folder in SAP portal 7.3 programmatically in webdynpro java.
    My requirement is in my portal 1000 transport packages is their. Now i want to move 1 to 200 TP's into Archive folder.
    Can you please help me how to do in through portal or wd java ...
    Regards
    Chakri

    Hello,
    Do you know what the difference between copying a file this way :
    ** Fast & simple file copy. */
    public static void copy(File source, File dest) throws IOException {
    FileChannel in = null, out = null;
    try {         
    in = new FileInputStream(source).getChannel();
    out = new FileOutputStream(dest).getChannel();
    long size = in.size();
    MappedByteBuffer buf = in.map(FileChannel.MapMode.READ_ONLY, 0, size);
    out.write(buf);
    } finally {
    if (in != null) in.close();
    if (out != null) out.close();
    ================SECOND WAY============
    AND THIS WAY:
    // Move file (src) to File/directory dest.
    public static synchronized void move(File src, File dest) throws FileNotFoundException, IOException {
    copy(src, dest);
    src.delete();
    // Copy file (src) to File/directory dest.
    public static synchronized void copy(File src, File dest) throws IOException {
    InputStream in = new FileInputStream(src);
    OutputStream out = new FileOutputStream(dest);
    // Transfer bytes from in to out
    byte[] buf = new byte[1024];
    int len;
    while ((len = in.read(buf)) > 0) {
    out.write(buf, 0, len);
    in.close();
    out.close();
    And which is better? I read up on what each kind of does but still a bit unclear as to when it is good to use which.
    Thanks in advance,
    JavaGirl

  • I am not being able to play sound when I import a .MTS file from my folder

    I am not being able to play sound when I import a .MTS file from my folder on my sequence bar of my Premiere Pro CS6. Even if I use my Media Browser to import the file, the video plays fine, but the audio is disabled it seems. I don't know what to do since I have used .MTS files before without hassle on CS5.5. It is quite frustrating. What can I do?

    Hi debesh05,
    Please mention the Operating System that you are using and also make and model of the Camera that was used to capture those clips. Also, try to make another folder with the same name in the same location where the .MTS files are and move all the clips into the new folder and then try to import the files again using Media Browser in Premiere Pro CS6. If this doesn't work then make a copy of one file and rename it as .M2TS and then import that single file into Premiere Pro CS6. Please update if either of the solution works for you.
    Regards,
    Vinay

  • Auto scan files from windows folder

    I am having trouble updating the iTunes library automatically? e.g. when I delete a file from my folder where all my music is stored the Library in iTunes does not do a refresh and pick up the change?
    Please help because this is getting irritating because I have to keep importing the folder into iTunes.

    iTunes does not have an auto-refresh or scan feature as you desire.
    If you delete a music file on the PC (outside of iTunes), you will be left with a broken song reference within iTunes.
    Delete both the reference and file by using iTunes.

  • Importing All the files from a folder at a time

    Hi....
    Can any body tell me how to import set of files from a folder into IDM.
    It is becoming very difficult to import the files one after other....
    Waiting for Reply....
    Thanks in advance..........

    We used an ant script to build an XML file that will contain the files. The script is configured to use the folder structure of our CVS repository.
    We'd checkout our XML module and then run the build script and import the resulting init file.
    Code to the script is below -- caveat emptor. You'll need to change the folder structure to suit your own environment.
    <?xml version="1.0" encoding="UTF-8"?>
    <project basedir="." default="all" name="MyInit">
        <target name="init">
            <property location="." name="src.dir"/>
            <property location="." name="dest.dir"/>       
            <property name="project.name" value="${ant.project.name}"/>
            <property location="${dest.dir}/MyInit.xml" name="MyInit.output"/>
            <property name="source.configuration" value="${dest.dir}/configuration"/>       
            <property name="source.emailTemplate" value="${dest.dir}/emailTemplate"/>
            <property name="source.forms" value="${dest.dir}/forms"/>
            <property name="source.reports" value="${dest.dir}/reports"/>               
            <property name="source.resource" value="${dest.dir}/resource"/>          
            <property name="source.rules" value="${dest.dir}/rules"/>
            <property name="source.workflow" value="${dest.dir}/workflow"/>
            <!-- get the source path -->
            <path id="configuration.path">
                <fileset dir="${source.configuration}" >
                   <include name="*.xml" />
                </fileset>
             </path>
             <property name="cp" refid="configuration.path" />
             <path id="emailTemplate.path">
                <fileset dir="${source.emailTemplate}" >
                   <include name="*.xml" />
                </fileset>
             </path>
             <property name="ep" refid="emailTemplate.path" />
             <path id="forms.path">
                <fileset dir="${source.forms}" >
                   <include name="*.xml" />
                </fileset>
             </path>
             <property name="fp" refid="forms.path" />
            <path id="reports.path">
                <fileset dir="${source.reports}" >
                   <include name="*.xml" />
                </fileset>
             </path>
             <property name="rptp" refid="reports.path" />                 
            <path id="resource.path">
                <fileset dir="${source.resource}" >
                   <include name="*.xml" />
                </fileset>
             </path>
             <property name="rep" refid="resource.path" />        
            <path id="rules.path">
                <fileset dir="${source.rules}" >
                   <include name="*.xml" />
                </fileset>
             </path>
             <property name="rp" refid="rules.path" />
            <path id="workflow.path">
                <fileset dir="${source.workflow}" >
                   <include name="*.xml" />
                </fileset>
             </path>
             <property name="wp" refid="workflow.path" />
            <!-- get the path prefix -->
             <path id="source.path">
                <pathelement location="${src.dir}" />
             </path>
             <property name="sp" refid="source.path" />       
        </target>
        <target depends="init"  name="win_init">
            <!-- change the path of xml files to windows path -->
            <property name="importfile.path" value="${sp}"/>                            
        </target>              
        <target depends="init" name="make">
        <!-- using XML character entity references to escape
        <  <
        >  >
        '  &apos;      -->    
            <echo file="${MyInit.output}" append="false"><?xml version='1.0' encoding='UTF-8'?>
    <!DOCTYPE Waveset PUBLIC 'waveset.dtd' 'waveset.dtd'>
    <Waveset>
    ${cp}
    ${ep}
    ${fp}
    ${rptp}
    ${rp}
    ${wp}
    </Waveset>
            </echo>
         <!-- replace path prefix with ImportCommand -->
         <replace file="${MyInit.output}"
                  token = "${sp}"
                  value = "<ImportCommand name='include' file='${importfile.path}" />
         <!-- deal with file and path separators in an os independent way -->
         <replace file="${MyInit.output}"
                  token = "${file.separator}"
                  value = "/" />        
        <replace file="${MyInit.output}"
                  token = "${path.separator}"
                  value = "${line.separator}" />
        <replace file="${MyInit.output}"
                  token = ".xml"
                  value = ".xml'/>" />
        </target>
        <target depends="init,win_init,clean,make" description="Build everything." name="all"/>
        <target depends="init" description="Clean all build products." name="clean">
            <delete file="${MyInit.output}"/>
        </target>
    </project>

  • I have installed itunes 11.0.2.26. When I delete a file or podcast I am not being prompted to delete the file from its folder at the same time.

    I have installed itunes 11.0.2.26. When I delete a file or podcast I am not being prompted to delete the file from its folder at the same time. How do I restore this facility? I am running a 64bit Windows 7 OS

    Is the media files in question in the iTunes library or elsewhere on the computer?

  • Is it possible to pickup a specific file from a folder?

    Hi
    I am wondering whether it is possible to pick a specific file from a folder. I have a shape where I have got a filename and I need to look for it in a folder.
    Is that possible?
    And how can I achieve this? The next step is to pick the file up and transfer it to another location. So basically in pseudo code I need to ask my defined folder with a filename as parameter. Get the file and move it to another folder.
    Suggestions are most appreciated. Thanks

    Assuming you are using orchestration, you could
    create an assembly, install it in the GAC, add a reference to it in your BTS
    project, and call it from an Expression shape to resolve the receive
    location. You would only really need one static method in a class. Be sure
    to add a reference to Microsoft.BizTalk.ExplorerOM.dll.
    Example:
    using Microsoft.BizTalk.ExplorerOM;
    namespace Phil
    public class OrchestrationHelpers
    public static string ResolveReceiveLocationName(string
    inboundTransportLocation, string receivePortName)
    BtsCatalogExplorer bts = new BtsCatalogExplorer();
    bts.ConnectionString =
    "SERVER=localhost;DATABASE=BizTalkMgmtDb;Trusted_Connection=True;Network
    Library=DBMSSOCN;"
    foreach (ReceiveLocation location in
    bts.ReceivePorts[receivePortName].ReceiveLocations)
    if (location.Address == inboundTransportLocation) return location.Name;
    return null;
    In your Expression shape within your orchestration, assuming a message
    called "MyMessage" and a string variable "receiveLocationName":
    receiveLocationName =
    Phil.OrchestrationHelpers.ResolveReceiveLocationName(MyMessage(BTS.InboundTransportLocation),
    MyMessage(BTS.ReceivePortName));
    If this post answers your question, please mark it as such. If this post is helpful, click 'Vote as helpful'.

  • How can I move a Pages file from a folder to another one?

    I Have done the upgrade to mac os Yosemite but now i'm Not able to move a file from a folder to another one Inside iCloud
    now it's impossible to organize MY archive

    Thankyou Winston, you guess right. What i don't understand is why with the older version of mac os (10.9) i can organize my document into icloud folders using the Pages app window. But now with the new version i'm no longer able to do that. Using ipad in the same window there is no problem, but in mac os it doesn't work. 

  • How to get latest added file from a folder using apple script

    Hi..
    I am trying to get a latest added file from a folder..and for this i have below script
    tell application "Finder"
        set latestFile to item 1 of (sort (get files of (path to downloads folder)) by creation date) as alias
        set fileName to latestFile's name
    end tell
    By using this i am not able to get latest file because for some files the creation date is some older date so is there any way to get latest file based on "Date Added" column of a folder.

    If you don't mind using GUI Scripting (you must enable access for assistive devices in the Accessibility System Preference pane), the following script should give you a reference to the last item added to any folder. Admittedly not the most elegant solution, but it works, at least under OS X 10.8.2.
    set theFolder to choose folder
    tell application "Finder"
        activate
        set theFolderWindow to container window of theFolder
        set alreadyOpen to exists theFolderWindow
        tell theFolderWindow
            open
            set theInitialView to current view
            set current view to icon view
        end tell
    end tell
    tell application "System Events" to tell process "Finder"
        -- Arrange by None:
        set theInitialArrangement to name of menu item 1 of menu 1 of menu item "Arrange By" of menu 1 of menu bar item "View" of menu bar 1 whose value of attribute "AXMenuItemMarkChar" is "✓"
        keystroke "0" using {control down, command down}
        -- Sort by Date Added:
        set theInitialSortingOrder to name of menu item 1 of menu 1 of menu item "Sort By" of menu 1 of menu bar item "View" of menu bar 1 whose value of attribute "AXMenuItemMarkChar" is "✓"
        keystroke "4" using {control down, option down, command down}
        -- Get the name of the last item:
        set theItemName to name of image 1 of UI element 1 of last scroll area of splitter group 1 of (window 1 whose subrole is "AXStandardWindow")
        -- Restore the initial settings:
        click menu item theInitialSortingOrder of menu 1 of menu item "Sort By" of menu 1 of menu bar item "View" of menu bar 1
        click menu item theInitialArrangement of menu 1 of menu item "Arrange By" of menu 1 of menu bar item "View" of menu bar 1
    end tell
    tell application "Finder"
        set current view of theFolderWindow to theInitialView -- restore the initial view
        if not alreadyOpen then close theFolderWindow
        set theLastItem to item theItemName of theFolder
    end tell
    theLastItem
    Message was edited by: Pierre L.

Maybe you are looking for

  • Can I use a iTunes card for iTunes match?

    Igot a 25 dollar iTunes gift card and I tried redeeming it for iTunes match but it wont let me it still says I need a credit card on file.  Whats the deal APPLE? Can I use the gift card, if not what do I have to do?

  • IMac no longer able to see HP wireless Printer

    My iMac, which I update regularly can no longer see my HP Photosmart 5510d wireless printer. OS X V10.9.5  2.7 Ghz Intel Core i5, 8 GB 1600 Mhz DDR3 It was working fine until a week or two ago and now it can't see it. I printed out my printer network

  • Automator To Search Multiple Sites?

    Not sure if this is possible since I'm new to Automator, but I tried and can't figure it out. I'd like to search roughly 5 web sites with one seach term. Here's what I've done so far: - Added 'Ask Text' Action - Added both get specific URL and Displa

  • Best way to solve ORA-01722: invalid number

    Hi, I recently had to debug a large Merge statement that was getting 'ORA-01722: invalid number' and I found the only way to do it was comment out the columns until I found the culprit :-( Surely in this day and age there is a better way to do this?

  • How to "ease in" to a key frame

    Hi is there some way i can ease in to a key frame, so that for instance if the key frame was a motion keyframe rather than the motion start sharply when the keframe was reached the motion  started slowly a defined time before the key frame  and built