ZIP in the FasadeBean

Hello. I have a complete FasadeBean.java file with some methods like below:
package sensei.services;
import java.util.*;
import javax.ejb.*;
import javax.naming.NamingException;
import org.apache.commons.logging.*;
import sensei.exceptions.opinion.*;
import sensei.exceptions.File.*;
import sensei.interfaces.*;
import sensei.interfaces.FileLocal;
import sensei.util.*;
import sensei.value.OpinionValue;
import sensei.value.FileValue;
* Klasa Facade dla modulu plikow.
* @author Adam Joka
* @ejb.bean      name = "FileServices"
*                     display-name = "FileServices EJB"
*                     description = "EJB that acts as a FileServices"
*                    type = "Stateless"
*                     view-type = "remote"
*                     jndi-name = "ejb/FileServices"
public abstract class FileServicesBean implements SessionBean {
    private static Log log = LogFactory.getLog(FileServicesBean.class);
    private SessionContext sessionContext;
    private FileLocalHome fileLocalHome;
      * @throws CreateException
      * @ejb.create-method
     public void ejbCreate() throws CreateException {
         try {
             fileLocalHome = FileUtil.getLocalHome();
         } catch (NamingException ex) {
             throw new CreateException("Cannot lookup LocalHome!: " + ex.getMessage());
     public void setSessionContext(SessionContext sessionContext) {
         this.sessionContext = sessionContext;
      * @ejb.interface-method
      * @param title
      * @throws FileCreateException
     public FileValue addFile(String session, String filename, byte[] fileData)
       throws FileCreateException {
         try {
              FileLocal fl = fileLocalHome.create(session, filename, fileData);   
             log.info("Created File: " + fl);
             return fl.getFileValue();
         } catch (CreateException ex) {
             throw new FileCreateException("Cannot create File: " + ex.getMessage());
      * @ejb.interface-method
     /*public void removeFile(String session) throws FileRemoveException, FileNotFoundException {
         try {
             FileLocal fileLocal = fileLocalHome.findByPrimaryKey(session);
             fileLocal.remove();
         } catch (RemoveException ex) {
             throw new FileRemoveException("Cannot remove File: " + ex.getMessage());
         } catch (FinderException ex) {
             throw new FileNotFoundException("Cannot find File to be removed: " + ex.getMessage());
      * @ejb.interface-method
     /*public Collection getAllFileValues() throws FileException {
         Collection r = new ArrayList();
         try {
             Collection files = fileLocalHome.findAll();
             for (Iterator it = files.iterator(); it.hasNext(); ) {
                  FileLocal file = (FileLocal) it.next();
                  FileValue fileValue = file.getFileValue();
                  log.info("getAllFileValues(): adding to collection: " + fileValue);
                   r.add(fileValue);
              return r;
         } catch (FinderException ex) {
             throw new FileException("Cannot find in getAllFileValues: " + ex.getMessage());
      * @ejb.interface-method
     /*public byte[] getFile(int fileId) throws FileException {
          try {
             FileLocal file = fileLocalHome.findByPrimaryKey(new Integer(fileId));
              log.info("getAllFile: getting file from File " + fileId);
              return file.getFileData();
         } catch (FinderException ex) {
             throw new FileException("Cannot find in getFileFile: " + ex.getMessage());
      * @ejb.interface-method
     /*public String getFilename(int fileId)throws FileException{
          try {
             FileLocal file = fileLocalHome.findByPrimaryKey(new Integer(fileId));
              log.info("getAllFile: getting filename from File " + fileId);
              return file.getFilename();
         } catch (FinderException ex) {
             throw new FileException("Cannot find in getFilename: " + ex.getMessage());
      * @ejb.interface-method
     /*public String getFileSession(int fileId) throws FileException{
          try{
               FileLocal file = fileLocalHome.findByPrimaryKey(new Integer(fileId));
               log.info("getFileSession: getting session of file " + fileId);
               return file.getSession();
          catch(FinderException ex){
               throw new FileException("Canot find in getFileSession: " + ex.getMessage());
      * @ejb.interface-method
     public Collection getFilesValuesBySession(String session) throws FileException{
          Collection r = new ArrayList();
         try {
             Collection files = fileLocalHome.findAll();
             for (Iterator it = files.iterator(); it.hasNext(); ) {
                  FileLocal file = (FileLocal) it.next();
                  FileValue fileValue = file.getFileValue();
                  if(fileValue.getSession().equals(session)){
                       log.info("getAllFileValues(): adding to collection: " + fileValue);
                       r.add(fileValue);
              return r;
         } catch (FinderException ex) {
             throw new FileException("Cannot find in getFilesBySession: " + ex.getMessage());
}Now I have to add such a method to this FacadeBean file which could be responsible to unpack the zip and add every file that was inside this zip archive to the database. I've already found a class responsible to unpack the zip files:
import java.io.*;
import java.util.*;
import java.util.zip.*;
public class UnZip {
   public static void main (String argv[]) {
      try {
         final int BUFFER = 2048;
         BufferedOutputStream miejsce = null;
         FileInputStream fis = new FileInputStream("io.zip");
         CheckedInputStream checksum = new
         CheckedInputStream(fis, new Adler32());
         ZipInputStream zis = new
         ZipInputStream(new
         BufferedInputStream(checksum));
         ZipEntry entry;
         while((entry = zis.getNextEntry()) != null) {
            System.out.println("Rozkapowywanie: " +entry);
            int count;
            byte data[] = new byte[BUFFER];
            FileOutputStream fos = new
            FileOutputStream(entry.getName());
            miejsce = new BufferedOutputStream(fos,BUFFER);
            while ((count = zis.read(data, 0, BUFFER)) != -1)
               miejsce.write(data, 0, count);
            miejsce.flush();
            miejsce.close();
         zis.close();
         System.out.println("Suma kontrolna: "+checksum.getChecksum().getValue());
      } catch(Exception e) {
         e.printStackTrace();
} Could anybody please help me with 'connecting' these two applications to obtain a method in the FasadeBean file that could unpack the zip archive?
Regards

Or maybe somebody could help with changin whole UnZip class to the method...please :( ?

Similar Messages

  • Java.lang.Error: java.util.zip.ZipException: The system cannot find the fil

    I got maven 221 installed
    i got jdk 1.6 and 1.5 installed (have tested both)
    I have a strange error. All my co-workers can build but I cant. The only thing I can find is that I dont have installed BEA Weblogic but I dont want to have that installed. It should be able to run anyway.
    Could someone tell me what is wrong? If you need pom.xml I got that one as well.
    process-classes:
    [copy] Copying 4 files to C:\hudson\jobs\albpm_ip-identity-asserter_-_Build\workspace\target\mbean-content
    [mkdir] Created dir: C:\hudson\jobs\albpm_ip-identity-asserter_-_Build\workspace\target\mbean-jar
    [java] Creating an MJF from the contents of directory C:\hudson\jobs\albpm_ip-identity-asserter_-_Build\workspace\target\mbean-content...
    [java] Compiling the files...
    [java] Creating the list.
    [java] Doing the compile.
    [java] WLMaker-SubProcess: : Exception in thread "main" java.lang.Error: java.util.zip.ZipException: The system cannot find the file specified
    [java] WLMaker-SubProcess: :      at weblogic.management.commo.BeanGenDriver.getManagementTempDir(BeanGenDriver.java:93)
    [java] WLMaker-SubProcess: :      at weblogic.management.commo.BeanGenDriver.main(BeanGenDriver.java:117)
    [java] WLMaker-SubProcess: : Caused by: java.util.zip.ZipException: The system cannot find the file specified
    [java] WLMaker-SubProcess: :      at java.util.zip.ZipFile.open(Native Method)
    [java] WLMaker-SubProcess: :      at java.util.zip.ZipFile.<init>(ZipFile.java:203)
    [java] WLMaker-SubProcess: :      at java.util.jar.JarFile.<init>(JarFile.java:132)
    [java] WLMaker-SubProcess: :      at java.util.jar.JarFile.<init>(JarFile.java:97)
    [java] WLMaker-SubProcess: :      at weblogic.management.commo.BeanGenDriver.getManagementTempDir(BeanGenDriver.java:90)
    [java] WLMaker-SubProcess: :      ... 1 more
    [java] WLMaker-SubProcess: : Stopped draining WLMaker-SubProcess:
    [java] WLMaker-SubProcess: : Stopped draining WLMaker-SubProcess:
    [java] BeanGen code generation failed
    [HUDSON] Archiving C:\hudson\jobs\albpm_ip-identity-asserter_-Build\workspace\pom.xml to C:\hudson\jobs\albpmip-identity-asserter_-Build\modules\dk.skat.ip.integration.albpm$ip-identity-asserter\builds\2010-11-2213-41-28\archive\dk.skat.ip.integration.albpm\ip-identity-asserter\1.2\pom.xml
    [INFO] ------------------------------------------------------------------------

    from my experience, using weblogic jars can be a pain if the full install is not on the local box.
    Note that you dont have to 'install' it. Just copy the directory.
    Reason is that the jar files have manifests with relative classpaths.
    For an example of horror take a look at the weblogic.jar MANIFEST's classpath entry.
    -Fred

  • I use javaFx WebViewBrowser to download ZIP file, the page no action

    I use javaFx WebViewBrowser to download ZIP file, the page no action; other tools example chrome ,ie can download the zip file .
    so can you writer a download zip file example for me ?
    thanks ,my english is so bad ,sorry !!! :)

    WebView doesn't have a built in file downloader - you have to implement it yourself.
    You can find a sample implementation for file downloads in JavaFX here =>
    http://www.zenjava.com/2011/11/14/file-downloading-in-javafx-2-0-over-http/
    That sample does not include the hooks into WebView to trigger the downloads.
    You will need to trigger off the mime type or the file extension in the url.
    A rudimentary sample trigger a download off of webview is provided in the code below.
    For a nice solution, you would probably want to spin the downloader off with it's own UI similar and manage the download itself as a JavaFX Task similar to how the zenjava component works.
    Code adapted from => http://code.google.com/p/willow-browser/source/browse/src/main/java/org/jewelsea/willow/BrowserWindow.java
    // monitor the location url, and if it is a pdf file, then create a pdf viewer for it, if it is downloadable, then download it.
    view.getEngine().locationProperty().addListener(new ChangeListener<String>() {
      @Override public void changed(ObservableValue<? extends String> observableValue, String oldLoc, String newLoc) {
        if (newLoc.endsWith(".pdf")) {
          try {
            final PDFViewer pdfViewer = new PDFViewer(false);  // todo try icepdf viewer instead...
            pdfViewer.openFile(new URL(newLoc));
          } catch (Exception ex) {
            // just fail to open a bad pdf url silently - no action required.
        String downloadableExtension = null;  // todo I wonder how to find out from WebView which documents it could not process so that I could trigger a save as for them?
        String[] downloadableExtensions = { ".doc", ".xls", ".zip", ".tgz", ".jar" };
        for (String ext: downloadableExtensions) {
          if (newLoc.endsWith(ext)) {
            downloadableExtension = ext;
            break;
        if (downloadableExtension != null) { 
          // create a file save option for performing a download.
          FileChooser chooser = new FileChooser();
          chooser.setTitle("Save " + newLoc);
          chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Downloadable File", downloadableExtension));
          int filenameIdx = newLoc.lastIndexOf("/") + 1;
          if (filenameIdx != 0) {
            File saveFile = chooser.showSaveDialog(view.getScene().getWindow());
            if (saveFile != null) {
              BufferedInputStream  is = null;
              BufferedOutputStream os = null;
              try {
                is = new BufferedInputStream(new URL(newLoc).openStream());
                os = new BufferedOutputStream(new FileOutputStream(saveFile));
                int b = is.read();
                while (b != -1) {
                  os.write(b);
                  b = is.read();
              } catch (FileNotFoundException e) {
                System.out.println("Unable to save file: " + e);
              } catch (MalformedURLException e) {
                System.out.println("Unable to save file: " + e);
              } catch (IOException e) {
                System.out.println("Unable to save file: " + e);
              } finally {
                try { if (is != null) is.close(); } catch (IOException e) { /** no action required. */ }
                try { if (os != null) os.close(); } catch (IOException e) { /** no action required. */ }
            // todo provide feedback on the save function and provide a download list and download list lookup.
    });

  • Where can I get Tutotorial.zip that the OA Framework Developer Guide talks

    Hi
    Can someone please tell me as to, from where I can get the Tutorial.zip that the OA Framework Developer Guide talks about.
    thanks
    subra.

    Hi,
    You can download the OA JDeveloper Extension from Metalink (Patch Number 4045639) and install it according to the instructions provided on Metalink note 286082.1. This will install a version of JDeveloper on your machine that already comes with the tutorial mentioned in the Developer Guide, as well as the IDE suited for OA Development.
    Thanks!
    Thiago

  • How to zip all the files generated using file adapter

    Hello Everyone,
    I have a scenario in place where i split a message into multiple messages. I used to generate multiple file using the file name present in the payload of the splitted message using variable substitution.
    This is working fine.
    Now the requirement has changed and i want to zip all these file and create a single zip file.
    I think it could be done using run OS command option in file adapter, but have no clue how to do it.
    Please help me.
    Regards
    Rahul Nawale

    Hi,
    you can use on of the command line ZIP utilities:
    http://www.winzip.com/prodpagecl.htm
    http://www.7-zip.org/
    then when your file adapter puts the file
    you can use commnad line to zip the files
    Regards,
    michal

  • I can't upload our packaged app. Each time I attempt to upload the zip file the system uploads it and then it gets stuck on the "validating .....zip" part. :(

    I have created an app in accordance with your requirements. Most notably, the app runs well and error free in your provided simulator. However, as I attempt to submit the app on the https://marketplace.firefox.com/developers/submit/ page, immediately after the .zip file (contains the required manifest.webapp in the root directory) is uploaded, the system just gets stuck at the "uploading APP.zip" part and I am never allowed to proceed. This is quite frustrating. Any help with this matter would be greatly appreciated.
    Regards,
    Ethan-Anthony

    Hi,
    This is more of an end user support forum so I'm not sure that many of the people here are best placed to answer questions about submitting apps to the marketplace.
    The best thing would probably be to connect to the #app-reviewers team via IRC. Then you can chat directly with them and get answers to your questions.
    See here for details on how to connect to IRC: https://wiki.mozilla.org/IRC
    Alternatively you can email: [email protected]
    Also see here for more information on Reviewers/Apps/Testing:
    https://wiki.mozilla.org/Marketplace/Reviewers/Apps/Testing

  • The pdk.zip at the link on Oracle-Site is bad

    The file on the link:
    http://otn.oracle.com/software/htdocs/devlic.html?http://download.oracle.com/otn/other/PDK.zip
    is corrup is ther a other link to download ?

    The file on the link:
    http://otn.oracle.com/software/htdocs/devlic.html?http://download.oracle.com/otn/other/PDK.zip
    is corrup is ther a other link to download ? The link seems to be fine, do you mean to say the pdk.zip file which u downloaded is corrupted. If so, I'm not sure of the exact reason of corrupt file getting downloaded, but it could be possible that your download did not complete. I tried today, it is fine and functional. You could try downloading again.

  • Why isn't there a "Get Files from Zip" on the zip pallette in 8.0?

    The zip pallette has three functions.  New Zip File, Add File to Zip, and Close Zip File.  I cannot figure why they would not include a way of extracting files from an existing zip. 
    All three have password protected block diagrams, so I cannot go monkeying around on my own.  Anyone have any ideas?

    The OpenG add-on LabVIEW library (which uses zlib) will do all that you ask and more.
    The installation process uses something called OpenG Commander and, while it can be a bit confusing, it is more than worth the trouble in the end!

  • Where can I find an uncompressed version -- or one that doesn't use 7-Zip -- of the Thunderbird installer?

    I'm trying to install Thunderbird on my work computer. However, our IT department has a company-wide block on 7-Zip, the compression program used in the Thunderbird installer. I'm looking for a way around this block. (I have approval to install Thunderbird, but they aren't going to turn off the block on 7-Zip to allow me to do so.)
    Are there uncompressed versions of the Thunderbird installer around somewhere? Or ones that don't include the 7-Zip extractor?
    Thanks in advance.

    The last Release of Firefox and Thunderbird to have a .zip version was the ancient Firefox 1.0.1 and Thunderbird 1.0 as they were .zip for Releases till then. They stopped with the .zip due to bad crashes caused by people installing the installer and .zip builds over each other and mixing. I would not recommend to use such old vulnerable versions.
    Maybe if need be you can extract it on another computer and transfer to your work computer by usb.

  • How to get the entries in a jar/zip file contained within a jar/zip file?

    If I want to list the jar/zip entries in a jar/zip file contained within a jar/zip file how can I do that?
    In order to get to the entry enumeration I need a Zip/JarFile:
    ZipFile zip = new ZipFile("C:/java_dev/Java_dl/java_jdk_commander_v36d.zip");
    // Process the zip file. Close it when the block is exited.
    try {
    // Loop through the zip entries and print the name of each one.
    for (Enumeration list =zip.entries(); list.hasMoreElements(); ) {
    ZipEntry entry = (ZipEntry) list.nextElement();
    System.out.println(entry.getName());
    finally {
    zip.close();
    Zip file "java_jdk_commander_v36d.zip" contains two zip entries:
    1) UsersGuide.zip
    2) JDKcommander.exe
    How to list the entries in "jar:file:/C:/java_dev/Java_dl/java_jdk_commander_v36d.zip!/UsersGuide.zip"?
    The following code:
    URL url = new URL("jar:file:/C:/java_dev/Java_dl/java_jdk_commander_v36d.zip!/UsersGuide.zip");
    JarURLConnection jarConnection = (JarURLConnection)url.openConnection();
    zipFile = (ZipFile)jarConnection.getJarFile();
    would point to "jar:file:/C:/java_dev/Java_dl/java_jdk_commander_v36d.zip", which is no help at all and Class JarURLConnection does not have an enumeration method.
    How can I do this?
    Thanks.
    Andre

    I'm not sure I understand the problem. The difference between a zip and jar file is the manifest file; JarFile is extended from ZipFile and is able to read the manifest, other than that they are the same. Your code
    for (Enumeration list =zip.entries(); list.hasMoreElements(); ) {
    ZipEntry entry = (ZipEntry) list.nextElement();
    System.out.println(entry.getName());
    }is close to what I've use for a jar, below. Why not use the same approach? I don't understand what you're trying to do by using JarURLConnection - it's usually used to read the jar contents.
    String jarName = "";
    JarFile jar = null;
    try
        jar = new JarFile(jarName);
    catch (IOException ex)
        System.out.println("Unable to open jarfile" + jarName);
        ex.printStackTrace();
    for ( Enumeration en = jar.entries() ;  en.hasMoreElements() ;)
        System.out.println(en.nextElement());
    }

  • Setting the name of streamed zip file

    Hi,
    I have a servlet which creates a zip file with documents retrieved from a database. To create the zip file I am using the ZipOutputStream class and adding the documents one at a time to this object. This is all working fine.
    The problem I have is pretty simple, in that I can't seem to find a way in which to set the name of the zip file. This must be possible! At the moment it appears to be setting the name of the zip file to the name of the class that created it. In this case my class is called DocumentPacker and what comes back from the servlet is a zip file called DocumentPacker.zip. This wouldn't be so bad, but if you're creating the zip file for a user that does not have cookies enabled, it appends the session id to the end of the zip file name which i don't want.
    I am creating my ZipOutputStream like this:
    ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(response.getOutputStream()));
    and then adding the documents one at a time using a BufferedInputStream.).
    Any help on how to set the name would be much appreciated
    Thanks
    Claire

    Your servlet must set some headers on the HTTP response (Content-Type as "application/zip", Content-Disposition as "attachment; filename=yourfilename.zip")
    Read the RFC1806 document.
    Content-Type: application/zip
    Content-Disposition: attachment; filename=genome.jpeg

  • Need to send the zip file to mail as an attachment

    i want to pick the zip file which consists some 2,3 files inside it. and send as it is to mail as an attachment.what i did is
    i have taken one zip file,,, "testing.zip" inside it i have "test1.txt" & "test2.csv"
    i created sender CC ,,in that i used module payloadzipbean and  unzipped and called the file adapter.. created reciever CC as mail ..used same payload module now here i zipped all the payloads.
    Result..i see the attachment coming as "test1.txt.zip" ..here i can see inside this zipfile my original file names as "test1.txt"&"test2.csv" as i enabled ASMA in both CC.
    issues:i am unable to get the original file name like "testing.zip" ,,
    can anyone help me in this.
    Regards,
    Loordh

    Hi  all,
    as i posted last time my requirement ,i am going with java mapping for my scenario. i am using this code .
    http://wiki.sdn.sap.com/wiki/display/XI/Dynamicfilenameforpass-through+scenario
    this is working perfect for zip file  (file to file) scenario. but my scenario is file to mail ..as i need to send this to mail package there it is throwing error.i am getting  "zip file name as attachment properly but when  i try to  open it is giving error in zip file." this is what i modied code ..i am able to see my messge in sender CC and reciever CC..any java experts please help on this.
    try {
    // create XML structure of mail package
    String output = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
    + "<ns:Mail xmlns:ns=\"http://sap.com/xi/XI/Mail/30\">"
    + "<Subject>" + mailSubject + "</Subject>"
    + "<From>" + mailSender + "</From>"
    + "<To>" + mailReceiver + "</To>"
    + "<Content_Type>multipart/mixed; boundary=\"" + boundary + "\"</Content_Type>"
    + "<Content>";
    out.write(output.getBytes());
    // create the declaration of the MIME parts
    //First part
    output = "--" + boundary + CRLF
    + "Content-Type: text/plain; charset=UTF-8" + CRLF
    //+ "Content-Transfer-Encoding: 8bit" + CRLF
    + "Content-Disposition: inline" + CRLF + CRLF
    + mailContent + CRLF
    //Second part
    + "--" + boundary + CRLF
    + "Content-Type: Application/zip; name=" + attachmentName + CRLF
    //+ "Content-Transfer-Encoding: base64" + CRLF
    + "Content-Disposition: attachment; filename=" + attachmentName + CRLF + CRLF;
    out.write(output.getBytes());
    //Source is taken as attachment
    copySource(in, out);
    out.write("</Content></ns:Mail>".getBytes());
    } catch (IOException e) {
    throw new StreamTransformationException(e.getMessage());
    protected static void copySource(InputStream in, OutputStream out)
    throws IOException {
    byte[] bbuf = new bytehttp://in.available();
    int bblen = in.read(bbuf);
    if (!(bblen < 0)) {
    //String sbuf = new String(bbuf);
    //String encoded = Base64.encode(sbuf);
    // replace all control characters with escape sequences
    //sbuf = sbuf.replaceAll("&", "&");
    //sbuf = sbuf.replaceAll("\"", """);
    //sbuf = sbuf.replaceAll("'", "&apos;");
    //sbuf = sbuf.replaceAll("<"<");
    //sbuf = sbuf.replaceAll(">", ">");
    out.write(bbuf);}}

  • .ZIP files and the ZipFile object

    Dove into java.util.zip this weekend and was most unhappy with the docs. Fortunately, searching these forums I was able to make some progress, but am still confused about the ZipFile class.
    I was able to open a FileInputStream, hand it to a ZipInputStream and read a .ZIP file. I was not able to read the .ZIP opening it as a ZipFile (I got the ZipEntries and the header info, but couldn't unzip the data).
    I was able to write a .ZIP with the reverse but was concerned that the ZipFile isn't even documented as supporting file writing. Is the ZipFile a useful thing in some way I haven't discovered, or should I just forget about it?

    this is a simple test for copying a zip file
    java ZipDemo c:\myZip.zip d:\testdir
    import java.util.zip.*;
    import java.io.*;
    import java.util.*;
    class ZipDemo
         public static void main(String [] arg) throws Exception
              ZipFile src = new ZipFile(arg[0]);
              File tgt = new File(arg[1]);     
              if(!tgt.isDirectory())
                   System.out.println(tgt+" is not found, or not a directory");
              for(Enumeration e = src.entries(); e.hasMoreElements(); )
                   ZipEntry ze = (ZipEntry) e.nextElement();
                   File target = new File(tgt, ze.getName());
                   try {
                        target.getParentFile().mkdirs();
                   }catch(NullPointerException npe){} // ignore case where file has no parent
                   if(!ze.isDirectory())
                        copy(src.getInputStream(ze), target);
         static byte [] buffer = new byte [16384];
         public static void copy(InputStream in, File target) throws IOException
              FileOutputStream out = new FileOutputStream(target);
              int bytesRead;
              while((bytesRead=in.read(buffer))>0)
                   out.write(buffer,0,bytesRead);
              out.close();
              in.close();     
    }

  • Problem in unzipping the zip files

    Hi,
    I have created a program to unzip the zip files. But when i try to zip it is creating the zipped files outside the folder where it is to be zipped.
    what is wrong with my code.
    if the zip file is migration.zip
    if the path inside the zip file shows
    and the path inside says this
    /codebase/scripts/
    it would create migration folder and create codebase folder outside the migration folder
    what is wrong with my code
    //Unzip the zip files to the folder with their name
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.FilenameFilter;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.Enumeration;
    import java.util.zip.ZipEntry;
    import java.util.zip.ZipFile;
    // Getting the path to find the type of files
    public class zipper implements FilenameFilter{
              String ext;
              public zipper(String ext)
                   this.ext="." + ext;
              public boolean accept(File dir,String name)
                   return name.endsWith(ext);
    public static void main(String args[]) throws IOException
              try
                        String dir = "D:/a/";
                        File f2 = new File(dir);
                        FilenameFilter fn= new zipper("zip");
                        String ss[]=f2.list(fn);
                   for ( int j = 0; j < ss.length; j++)
                        System.out.println(" Extracting ...." + ss[j]) ;
                        String zipFile = dir + ss[j];
                        ZipFile zf = new ZipFile(zipFile);
                        Enumeration entries = zf.entries();
                        String directoryName = zf.getName();
                        directoryName = directoryName.substring(0, (directoryName.indexOf(":" + File.separator) + 2));
                             String folderName = zf.getName();
                             folderName = folderName.substring(0, folderName.lastIndexOf("."));
                             File file1 = new File(folderName);
                             //File file1 = new File(entries.getName());
                             file1.mkdir();
                   while (entries.hasMoreElements())
                             ZipEntry ze = (ZipEntry) entries.nextElement();
                             String path = directoryName + ze.getName() ;
                             String path1 = folderName + ze.getName();
                             //System.out.println(" : " + path);
                             if (ze.getName().endsWith("/"))
                                       File file = new File(path);
                                       file.mkdir();
                                       continue;
                                       //break;
                        BufferedReader bReader = new BufferedReader(new InputStreamReader(zf.getInputStream(ze)));
         StringBuffer fileBuffer = new StringBuffer(" ");
         String line ;
                        while ((line = bReader.readLine()) != null)
                                  fileBuffer.append(line);
                                  fileBuffer.append("\r\n");
                                  //line = line + "\r\n";
                                  //byte[] b = new byte[line.length()];
                                  //b =line.getBytes();
                                  //out.write();
                        String fileData = fileBuffer.toString();
         File f1 = new File(path);
                        f1.createNewFile();
                        //FileOutputStream out = new FileOutputStream(folderName + "/" + ze.getName());
                        FileOutputStream out = new FileOutputStream(path);
                        long size = ze.getSize();
                        byte[] data1 = new byte[fileData.length()];
                        for (int i = 0; i < fileData.length(); i++)
                                  data1[i] = (byte) fileData.charAt(i);
         out.write(data1);
         out.close();
                        bReader.close();                         
                   } catch (Exception e)
                             e.printStackTrace();
    Thanks in Advance
    Avinash

    String path = directoryName + ze.getName();
    String path1 = folderName + File.separator+ ze.getName();
    File f1 = new File(path); // pass path1 instead of path
    f1.createNewFile();
    FileOutputStream out = new FileOutputStream(path); // pass path1 instead of path

  • Setting the classpath of classes12.zip for Tomcat

    Hi
    I am using Apache Tomcat webserver and while trying to run a jsp page which intializes oracle.jdbc.driver.OracleDriver it throws an error
    java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
    Please suggest how to set the classpath of classes12.zip in Apache Tomcat
    My Code Snippett
    <%@ page import="java.util.*,java.sql.*,javax.servlet.*"%>
    <body>
         <%
         Connection con ;
         ResultSet rs ;
         Statement stmt ;
         ResultSetMetaData rsmd ;
         try{ 
         Class.forName("oracle.jdbc.driver.OracleDriver");
         catch(Exception e)
         out.println(e);//print the exception on the command prompt
    %>

    The simplest way to do this is to copy classes12.zip to the WEB-INF/lib directory. The JSP should then find this automatically.
    As a side note, that is an ancient JDBC driver - you might want to upgrade to something from this millennium.

Maybe you are looking for

  • Download File by url in another server? (Content-Disposition","attachment)

    Can the file be downloaded by a url in another server? ie. Server A: JSP program Server B: filepath + filename = "http://xxx.com/xx/x.doc" e.g.     response.setContentType("APPLICATION/OCTET-STREAM");        response.setHeader("Content-disposition",

  • Control size of window

    http://www.bigredrooster.com/news.html I would like the window to open up to a size that is equal on the right as it is on the left of the red bar a the top. Anyone know how to control that dimension?

  • DNB integration with FSCM SAP Credit management

    Hi, Any body worked on or integrated  DNB  with FSCM SAP Credit management ? if it is please share some information /document on integration. Thx DD

  • Can you loop effects in Captivate?

    Hello! I am trying to create the image of someone falling down a hole with the little speed lines trailing behind it.  I'd like to give it the image of falling for the entire time the user is on the slide.  Is there a way to loop effects to continue

  • How to print the grade of sal?.

    how to print grade based on sal. think my table is having ename,sal columns. how to print the grade?. where i have to write the code?. pls give some tips i want to print like grade      ename sal 1 abc0     5000 2     abc1     4000 2     abc2     400