Downloading zip files - problem

I have a program which is supposed to allow download of a zip file to the users PC and then write a record to a database showing that the user has downloaded the file.
When I try and read the file I have downloaded I get an error message which says the zip file is incomplete.
Here is the code which downloads the file
docname = material.getFilelocation().substring(slashpos+1,material.getFilelocation().length());
// reformat file name to work with getRealPath
material.setFilelocation(dirname+"\\" +docname);
//read data from file
sc= getServletContext();
String fileaddress = sc.getRealPath(material.getFilelocation());
File resfile = new File(fileaddress);
FileInputStream fileIn = new FileInputStream (resfile);
BufferedInputStream in = new BufferedInputStream(new DataInputStream(fileIn));
// Set up output to client
res.setContentType("application/zip");
res.addHeader("Content-Disposition", "inline;filename="+docname);
OutputStream ds=res.getOutputStream();
byte b[]=new byte[1024];
int len =0;
while ((len=in.read(b))>0) {
ds.write(b,0,len);
in.close();
getfilelocation has format -directory/filename.zip
Does anyone know why the file is incomplete?
Thanks
Suzan

while ((len=in.read(b))>0) {There you are. You stop reading the input when you
reach the first zero byte. The documentation for this
method says
"If no byte is available because the end of the
stream has been reached, the value -1 is returned."I doubt that's the problem. The API does say that -1 is returned on EOF, but if it isn't going to return -1, then it will read at least 1 byte, stuff that into the array, and return the number of bytes read - which won't be zero unless the size of the array passed to it is zero (which it isn't).

Similar Messages

  • Problem on windows xp with downloaded zip file

    Hi,
    I have written a JSP to download file which is as follows
    try
    response.setContentType("application/download");
    response.setHeader("Content-Disposition","attachment;filename=<FileName>");
    int iRead;
    FileInputStream stream = null;
    try
    File f = new File(<FilePath>);
    stream = new FileInputStream(f);
    while ((iRead = stream.read()) != -1)
    out.write(iRead);
    out.flush();
    finally
    if (stream != null)
    stream.close();
    catch(Exception e)
    //out.println("Exception : "+e);
    After downloading zip file, could not extract files on windows XP by using any tool or built-in extractor i.e. compressed(zipped)folders (error: compressed folder invalid or corrupted).
    But this works on win2k or win98
    How can i work with it or can anyone tell me a solution to handle such a problem.
    Thanks in advance.
    Rajesh
    [email protected]

    This could be a problem with the built-in ZIP program in Win XP - it's possible that the ZIP you are downloading (uploading?) is simply incompatible with the XP program. In Win 98 & 2000, you would have to use your own ZIP program, e.g. Winzip, and that can handle more formats that the XP program.
    Try installing the same ZIP program that you have on w98/2k on your XP machine, and see if you can open the uploaded file using it.

  • Problem downloading ZIP file with Squid-3.0

    Hi,
    I have upgraded my Linux CentOS squid proxy servers to Squid version 3.0. Since then I can not download the following file it just hangs :
    http://download.oracle.com/otn/java/sqldeveloper/sqldeveloper-1.5.5.59.69.zip
    I dont see any error in the squid logs or on my firewall.
    I can however download it on one of the older servers still running Squid version 2.6.
    It is just very strange as I can download ZIP files from any other website with the upgraded servers.
    Any ideas on what might cause this ?
    Thanks
    JHEFER
    Edited by: jhefer on Nov 19, 2009 12:15 AM

    If you have already interested, I found the solution. The problem is that oracle website (and probably others) uses “Vary” field in the header and squid doesn’t support this (by default). You have to download squid sources on http://www.squid-cache.org/Versions/ and compile these with “--enable-http-violations” parameter :
    *./configure ‘--enable-http-violations’ ‘…’ ‘…’*
    make all
    make install
    I hope this solution will be very useful to you.
    Laurent

  • When i download zip files it says decompression failed

    when i download zip files on some occasions i get decompression failed

    The current version of the built-in Archive Utility has problems with some zip files. Use "The Unarchiver" instead -- free in the App Store.

  • How to create a Web Dynpro Project from Downloaded zip file?

    Hi,
    I have been working in Java Web Dynpro for last 1 month but not able
    to create any Web Dynpro from Downloaded zip file?
    Can anybody tell me how to create a Java Web Dynpro Project from
    Donloaded zip code?
    Regards
    Kaushik Banerjee

    Hi Kaushik,
    You can add the existing zip file into your workspace by the following way -
    First open the NWDS and create a new project by clicking file -> new -> Project -> Simple -> Project
    and then File -> Import -> zipfile and then browse the zip file into the newly created project.
    or else you can also unzip the zip file into a folder and then Use the option of Import an exisitng project into workspace. You can find this in the File-> import -> Existing project into workspace. and then use the Browse option to browse to the existing folder.
    After importing the project you need to rebuild the project
    Regards,
    Raju Bonagiri.

  • How do I get a download zip file from firefox to my desktop

    I download zip files from different web sites and they go to the download folder in firefox, but I can't access them to open,unzip, or work with them on my computer offline. How can I move them from the download folder in firefox to my computer desktop?

    Hi,
    In order to open ZIP files, you have to download an app to enable the opening of the ZIP. Here's one you can use: https://play.google.com/store/apps/details?id=com.winzip.android
    Next, when you install that, open it and go to your Download directory. It should either be in sdcard0, sdcard, or sdcard1, then go to Download.
    Once you find it, touch and hold the file, then click '''Unzip here''' and it will extract the files in the ZIP folder.
    Let me know if this works!

  • I am unable to download zip files

    http://avl1.teltonika.lt/Downloads.FM22
    I am unable to download zip files from this URL

    Thanks, I just needed to update (not to reset).

  • 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.
    });

  • Cant download zip.files

    Hi there,
    I cant download .zip files or software updates from any site and Ive tried several browsers.
    It just opens a new page and remains blank? or does nothing.
    I have no firewall on. And have no anti virus software.
    I can click on pdfs and they download fine.
    I using a new intel imac.
    Safari, firefox.
    Hope you can help, thanks.

    Fixed it, it was a program called speed downlod, i removed it and now i can download files, yay!
    speed downloader....more like Stop downloader

  • Can't download .zip files

    When downloading from file sharing sites, I can't download .zip files. Downloading other compressed files such as .rar is automatic upon clicking on the file. How do I change the settings to include .zip files. Thanks

    Below is a link I uploaded myself. It is a few random songs I zipped and uploaded to the file sharing service Hotfile. When I attempt to go to the link myself, safari will not open the page and it also will not auto download the file as it does with other compressed files such as .rar. If I compress the file in .rar format or simply upload an MP3 to Hotfile or Rapidshare, I can click on the link and it automatically downloads.
    Link http://hotfile.com/dl/48619201/97e4208/Archive_2.zip.html

  • Can't expand downloaded zip-files

    I download zip files and can't expand them. If I compress my own files, they are easily expanded. The error message reads: Unable to unarchive "document.zip" into "Desktop". (Error 1 - Operation not permitted.)
    I have tried to create a folder and drop the zipped file there and expand it. Checked permission, which are read & write.
    Any suggestions?

    Sorry, I just don't know for sure as I never use the archive function.
    As most of my stuff is either graphics or movies I have a deep mistrust of anything that might affect quality!

  • Informatica Powercenter 9.01 V26112-01_1of2 zip file problem

    Hi
    I have installed all three informatica zip files but Unfortunately V26112-01_1of2 zip file which contains License Key file and client doesnt work.
    it looks like corrupted. I have dowloaded three times but winzip, rar doesnt work with that zip file
    What can I do?
    thanks
    John
    BTW I am getting
    ! C:\Users\GoK\Desktop\Infa90\901HF2_Client_Installer_win32-x86_DOCS_KEY.z01: Cannot open C:\Users\GoK\Desktop\Infa90\901HF2_Client_Installer_win32-x86_DOCS_KEY.z01
    The system cannot find the file specified.
    ! Seek error in the file
    The system cannot find the file specified.
    Edited by: 877721 on Aug 6, 2011 2:13 PM

    Here is what readme says from Oracle..
    The parts titled "Oracle Business Intelligence Data Warehouse Administration Console 11g and Informatica PowerCenter and PowerConnect Adapters 9.0.1" and  “Oracle Business Intelligence Data Warehouse Administration Console 11g and Informatica PowerCenter andPowerConnect Adapters 9.1" include the Oracle Business Intelligence Data Warehouse Administration Console (DAC) 11g, Informatica PowerCenter Services and InformaticaPowerCenter Client Tools installers, the Informatica PowerCenter License Key and the InformaticaDocumentation.
    These parts are split into multiple downloads. Download all parts into the same directory location on a Windows machine.
    To extract the contents of the zip files:
    1.      Using WinZip, unzip the contents of each downloaded zip file into a single directory location. Do not give this directory a long name and avoid using the My Documents folder. On extraction of all the zip files, you will received additional zip files with file names similar to “dac_win_11g_infa_<OS and Bit>_<INFA version> and with file extensions .zip, .z01, .z02, .z03 etc.
    2.      Using WinZip, unzip the file with the .zip extension file into a new directory. Do not give this directory a long name and avoid using the My Documents folder. NOTE: Do not unzip the .z01, .z02 etc. files as the contents of these files will automatically be extracted.
    On extract of the zip files you will receive the following five files:
    1.     <INFA version>_Server_Installer_<OS> (.tar or .zip)
    2.      DAC11gInstaller.zip
    3.      910HF2_Client_Installer_win32-x86.zip
    4.      Infa91Docs.zip
    5.      Oracle_All_OS_Prod.key

  • Macbook Pro won't download .zip files correctly

    I have a Macbook Pro (13'' June 2012 model, 500GB HDD, 4GB RAM, 2.5GHz i5 processor, OS X 10.9.5) and whenever I try and download .zip files, on either Chrome or Safari, it doesn't know what size the file actually is meant to be (as seen below) and so keeps downloading constantly. Each time I cancel it (in some cases after it's reached over 100MB even though the file is a 9 song album), I get no files back out. Is there anyway to fix this so I can actually download them?

    Download Stuffit Expander from the App Store or directly from the manufacturer.  The software is free.  It can open any file you throw at it - after you set up its preferences to do so.

  • Downloading Zip files

    I use a Blackberry Storm 2 9520
    Why do I get a "Request Entity Too Large" message when I download a zip file, even if I've downloaded larger video files without having that problem.?

    see if this helps:
    Mail (Mountain Lion): View, save, and delete attachments

  • Cannot download zip file

    Why is it that with Firefox 8 I cannot download a zip file that was sent to me as an e-mail attachment? When I select the zip file a pop asks me if I want to 'open with' or 'save file'. Whichever option I choose the file is named attachment.ashx (this is not the name of the zip file I received).
    The only way I have been able to resolve the problem so far is to open the e-mail using Windows Explorer, from which I can retrieve the zip file correctly.

    I have the same problem since updating to Firefox 8 on my MacBook Pro. Now all files download as .ashx, sometimes I can open them via Word, but often they won't open at all. Previous versions of Firefox opened them in the appropriate application and saved them to the desktop. This has become such a problem that I have abandoned Firefox and have returned to Safari .....

Maybe you are looking for

  • ITunes freezes only when iPod is connected to USB

    Hello. Here's a real head-scratcher... I have an iPod touch (model MA627LL, sw version 2.2.1) that I've used with no problem on this computer for a long time. It had not synced since last April, so I tried this morning, and have been troubleshooting

  • Import export internal table

    Hi. How can i make an import export of an internal table but with the sap memory. Thanks. Regards Miguel

  • Bug (?) - TP3 - Date popup not work in query panel

    Steps: 1. In the data control pallette, expand a view object that has a date attribute 2. Drop the "All Queriable Attributes" named criteria onto a page and choose "Query -> ADF Query Panel With Table" 3. Run the page. Click on the icon next to the d

  • How do we create a custom format for printed contact information?

    We are trying to create a custom family directory for genealogical purposes.  Family members are individually saved as Outlook 2010 contacts with a special number field that (when parsed) designates their generation, birth order, and relationship to

  • Transport Req for Infoset - SQ02

    Hello all, First time I created a generic datasource based on Infoset . The Infoset is created in SQ02 (Joining 2 tables). Now I have problem in collecting this Infoset in the transport request. I tried doing in transport connection, but it collects