Getting download multiple files in zip format.

Hi
I am trying to read a zip file on c drive and send it for download on clients browser.
My problem is that when I am trying to read zip file form my system drive and copying it(Using NIO) on another location on my drive itself its working fine( working code is attached as Code 1)
but when I try to read zip file in MappedByteBuffer using NIO and append them in a string buffer after converting them to string and get them downloaded at client side, a zip file of same size as that on server is created but it doesn't open up. (Code attached as Code2)
Code1:
package com.pine.test;
import java.io.*;
import java.nio.*;
import java.nio.channels.FileChannel;
class copyFileUsingNIO{
     public static void main (String args[]) throws Exception{
          FileInputStream FIn;
          FileOutputStream FOut;
          FileChannel FIChan, FOChan;
          MappedByteBuffer mBuf;
          long FSize;
          try{
               FIn = new FileInputStream("c:\\Favorites.zip");
               FOut = new FileOutputStream("c:\\outfile_new.zip");
               FIChan = FIn.getChannel();
               FOChan = FOut.getChannel();
               FSize = FIChan.size();
               mBuf = FIChan.map(FileChannel.MapMode.READ_ONLY,0,FSize);
               StringBuffer sb = new StringBuffer();
               //System.out.println(mBuf.limit() + mBuf.toString());
               int len=0;
               byte[] b = new byte[1];
               while(len<mBuf.limit()){                     
                    b[0] = mBuf.get();
                    //System.out.print(b.toString());
                    String s = new String(b,0);
                    System.out.print(s);
                    sb.append(s);
                    //System.out.print(len);
                    len = len+1;
                    //System.out.print(s.toString());
               FOChan.write(mBuf);
               FIChan.close();
               FIn.close();
               FOChan.close();
               FOut.close();
          }catch(IOException ioe){
               System.out.println(ioe);
               System.exit(1);
          }catch(ArrayIndexOutOfBoundsException exc){
               System.out.println(exc.getStackTrace() + " hi");
               //System.exit(1);
//Code 2:-
package com.pine.test;
import java.io.*;
import java.nio.*;
import java.nio.channels.FileChannel;
class copyFileUsingNIO{
     public static void main (String args[]) throws Exception{
          FileInputStream FIn;
          FileOutputStream FOut;
          FileChannel FIChan, FOChan;
          MappedByteBuffer mBuf;
          long FSize;
          try{
               FIn = new FileInputStream("c:\\Favorites.zip");
FIChan = FIn.getChannel();
               FSize = FIChan.size();
               mBuf = FIChan.map(FileChannel.MapMode.READ_ONLY,0,FSize);
               StringBuffer sb = new StringBuffer();
               //System.out.println(mBuf.limit() + mBuf.toString());
               int len=0;
               byte[] b = new byte[1];
               while(len<mBuf.limit()){                     
                    b[0] = mBuf.get();
                    //System.out.print(b.toString());
                    String s = new String(b,0);
                    System.out.print(s);
                    sb.append(s);
                    //System.out.print(len);
                    len = len+1;
                    System.out.print(sb.toString());
               FIChan.close();
               FIn.close();
               FOut.close();
          }catch(IOException ioe){
               System.out.println(ioe);
               System.exit(1);
          }catch(ArrayIndexOutOfBoundsException exc){
               System.out.println(exc.getStackTrace() + " hi");
               //System.exit(1);
Can anyone tell me where I am wrong?
Thanks

but when I try to read zip file in MappedByteBuffer using NIO and append them in a string buffer after converting them to string and get them downloaded at client side, a zip file of same size as that on server is created but it doesn't open upSo don't do it that way.
BIJ001 is correct.

Similar Messages

  • Is it possible to download multiple files as zip from Amazone S3 directly

    We need to download multiple files from Amazone S3 at a time in a zipped format. We use flex 3 and coldfusion 8 for development.

    Of course it is. Try it. Or, asked differently, what did you try that did not work?

  • Download Multiple Files in one specified location

    Hi All,
    Suppose there are many documents which user wants to download in one specified location in local system.
    So is it possible in Web Dynpro Java?
    I have read documents on FileDownload UI Element and experimented on it. But I was not able to achieve the requirement.
    I was able to download single file at a time. So that means if there are 3 file to be downloaded, user will have to click on 3 different
    FileDownload UI Element, specify the path and download it.
    Can't we make it simple for user where he/she click FileDownload once and then all files get downloaded in that path.
    Best Regards,
    Gopal

    Hi Gopal,
    Using Filedownload UI Element, you can only able to download one file.
    But if you want to download group of files once. simply use java ZIP API(java.util.zip.*) to compress all the files into .zip format and download using the filedownload UI element.
    Regards,
    Naga

  • Download multiple files with 1 HttpURLConnection

    Hi,
    We have an application that downloads small text files (< 2 Kb) from a webserver. These files are downloaded 1 by 1 when needed. We open a HttpURLConnection, download 1 file and close the connection immediately afterwards. This is done for each file and hence produces a significant overhead.
    For performance reasons (both client and server side), we would like to open a connection to the webserver once, download a number of files and then close the connection.
    Currently, our code roughly looks like:
    InputStream is;
    HttpURLConnection con;
    int resp;
    try {
        URL url = new URL(location);
        con = (HttpURLConnection)url.openConnection();
        resp=con.getResponseCode();
        if(resp==HttpURLConnection.HTTP_OK) {
            is = con.getInputStream();
            // ... read data from the InputStream
            is.close();
    } catch (MalformedURLException murle) {
        murle.printStackTrace();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }Is it even possible to download multiple files from a web server using a HttpURLConnection? If so, how? :-)
    Please note that the solution should be compliant with J2SE 1.1, since we are writing an MHP application!
    Thanks in advance...

    Seerix,
    You might be able to fudge the settings of the URL class :
    Class URLStreamHandler
    Method protected void setURL
    Sets the fields of the URL argument to the indicated values. Only classes derived from URLStreamHandler are supposed to be able to call the set method on a URL.
    But this is not the best way, as URLs are supposed to be constant.
    Your alternative, is to create a Socket, deal with the protocol requirements
    (i.e. HTTP GET, POST and so on) then you can request any number files
    on that same connection. The only thing that this saves is connection build up and tear down.
    You could also multi-thread your original code ....... Although that might
    only save you some network transit time.
    -Cludge

  • Is it possible to download multiple files from FTP

    Hi,
    Is it possible to download the multiple zip files from FTP.I need to download multiple files from FTP into temporary folder in my local machine. Please help me.
    Regards,
    ahamad

    Of course it is. Try it. Or, asked differently, what did you try that did not work?

  • Download Multiple Files?? (Servlets/Jsp)

    Hello Forum Members,
    I need to download multiple files from Server on a single click of button thats says "download". Using Servlets/Jsp only( I don't want to use applets/or Zip the files).
    The scenario would be on the browser I will have 'n' number of checkboxes each corresponding to a file and there is a button that say's download. Once I click "download" the browser should prompt me to save in a directory.

    I don't know if there's a Java implementation already out there (i'm sure there must be), but I think you'd need a separate Download Manager to be able to handle multiple file downloads. I'm all but positive that the standard download isn't gonna cut it, especially if the user selects a whole bunch of files. I don't think the built in download function allows for more than one file to download at a time, so unless you want a whole bunch of download windows all going at once, you'll need to either find (or implement) something that can.

  • Download multiple files

    hi,all
    downloading files from server has been discussed for many times, i have known how to download one file after reading some older topics,but now i want to download
    multiple files,and I want browser prompt "Save As" only one time, then all the files would be downloaded to the same location,can anybody give me some advice?
    thanks & regards

    Hi,
    I don't think it sounds like what you're tyring to do would be possible for security reasons. I'd be quite worried if a browser was allowed to save multiple files after only asking once.
    I guess one solution would be to zip all the files up into one zip file (see JavaDocs for java.util.zip) and then transfer this zip file (this would also probably help with download times). This may not be the ideal solution for you though.

  • Downloading Excel File in CSV Format

    Hi All,
    How can I Download a file in .CSV Format?
    I am using the below shown code.
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
      BIN_FILESIZE                    =
        FILENAME                        = 'C:\Documents and Settings\sandeepp3\Desktop\sample.csv'
        FILETYPE                        = 'DAT'
      APPEND                          = ' '
        WRITE_FIELD_SEPARATOR           = ','
      HEADER                          = '00'
      TRUNC_TRAILING_BLANKS           = ' '
      WRITE_LF                        = 'X'
      COL_SELECT                      = ' '
      COL_SELECT_MASK                 = ' '
      DAT_MODE                        = ' '
      CONFIRM_OVERWRITE               = ' '
      NO_AUTH_CHECK                   = ' '
      CODEPAGE                        = ' '
      IGNORE_CERR                     = ABAP_TRUE
      REPLACEMENT                     = '#'
      WRITE_BOM                       = ' '
      TRUNC_TRAILING_BLANKS_EOL       = 'X'
      WK1_N_FORMAT                    = ' '
      WK1_N_SIZE                      = ' '
      WK1_T_FORMAT                    = ' '
      WK1_T_SIZE                      = ' '
      WRITE_LF_AFTER_LAST_LINE        = ABAP_TRUE
      SHOW_TRANSFER_STATUS            = ABAP_TRUE
    IMPORTING
      FILELENGTH                      =
      TABLES
        DATA_TAB                        = ITAB
        FIELDNAMES                      = HTAB
    EXCEPTIONS
      FILE_WRITE_ERROR                = 1
      NO_BATCH                        = 2
      GUI_REFUSE_FILETRANSFER         = 3
      INVALID_TYPE                    = 4
      NO_AUTHORITY                    = 5
      UNKNOWN_ERROR                   = 6
      HEADER_NOT_ALLOWED              = 7
      SEPARATOR_NOT_ALLOWED           = 8
      FILESIZE_NOT_ALLOWED            = 9
      HEADER_TOO_LONG                 = 10
      DP_ERROR_CREATE                 = 11
      DP_ERROR_SEND                   = 12
      DP_ERROR_WRITE                  = 13
      UNKNOWN_DP_ERROR                = 14
      ACCESS_DENIED                   = 15
      DP_OUT_OF_MEMORY                = 16
      DISK_FULL                       = 17
      DP_TIMEOUT                      = 18
      FILE_NOT_FOUND                  = 19
      DATAPROVIDER_EXCEPTION          = 20
      CONTROL_FLUSH_ERROR             = 21
      OTHERS                          = 22
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    I am getting the field separator as Tab(SPACE).
    Please Advise

    Hi Anil,
    Try this way.
    REPORT ztest_notepad.
    "Declarations
    TYPE-POOLS :truxs.
    DATA : it_download TYPE truxs_t_text_data.
    DATA: BEGIN OF it_data OCCURS 0,
            arbgb TYPE t100-arbgb,
            msgnr TYPE t100-msgnr,
            text TYPE t100-text,
          END OF it_data.
    START-OF-SELECTION.
      "Select Data
      SELECT * FROM t100
      INTO CORRESPONDING FIELDS OF TABLE it_data UP TO 200 ROWS   WHERE sprsl = sy-langu.
      "Convert SAP to CSV format
      CALL FUNCTION 'SAP_CONVERT_TO_CSV_FORMAT'
        EXPORTING
          i_field_seperator    = ';'
        TABLES
          i_tab_sap_data       = it_data
        CHANGING
          i_tab_converted_data = it_download
        EXCEPTIONS
          conversion_failed    = 1
          OTHERS               = 2.
      IF sy-subrc = 0.
        "Download data using GUI_DOWNLOAD
        CALL FUNCTION 'GUI_DOWNLOAD'
          EXPORTING
            filename = 'C:\test.txt'
            filetype = 'ASC'
          TABLES
            data_tab = it_download.
      ENDIF.
    Thanks
    venkat.O

  • Download multiple files in one step

    Hi,
    my first try with acrobat.com with uploading some pictures which I like to share with friends led me to the question, how they can download my 18 pictures in one step. I put them in a workspace and gave them access. You can mark all files, but there is no menu point which offers you to download all files in one step.
    Is there a way to do this in one step?
    Greetings
    Mario

    Hello Mario,
    Thank you for posting. Unfortunately, there is currently no way to download multiple files at once; this functionality is high on our list of planned enhancements, so I encourage you to stay tuned for future releases.
    Best regards,
    Rebecca

  • Aria2 does not download multiple files at a time

    I'm trying to speed up my system upgrades by using aria2, but it won't speed up anything as it does not download multiple files at a time.
    As per this wiki post, https://wiki.archlinux.org/index.php/Im … erformance , "using aria2", I've installed aria2 and added the line
    XferCommand = /usr/bin/aria2c --allow-overwrite=true -c --file-allocation=none --log-level=error \
    -m2 --max-connection-per-server=2 --max-file-not-found=5 --min-split-size=5M --no-conf \
    --remote-time=true --summary-interval=60 -t5 -d / -o %o %u
    to the options section in pacman.conf. Pacman still works, but it isn't sped up. When pacman -Syu'ing, a normal line shows:
    #1 SIZE:1.3MiB/2.0MiB(63%) CN:1 SPD:50.0KiBs ETA:15s
    What's going on?
    P.S. I use the line reflector -l 5 --sort rate --save /etc/pacman.d/mirrorlist before doing a system upgrade.
    Last edited by bruno321 (2011-05-15 15:27:45)

    Using aria2c will download files over 5MB with multiple connections but will not download multiple files at the same time. Pacman calls aria2c with the first url, waits for it to finish, then calls aria2c with the second etc...
    If you want to download multiple packages simultaneously, see http://xyne.archlinux.ca/projects/pacman2aria2/

  • OSD: Downloading multiple files is very slow

    I has a exe software. It is not a single file package, it contains a lot of files. when I installed this software in OSD, I found it would spend 15~20minutes to download files.
    It was very strange. The software is only 750 mb size. the speed of downloading 6 GB OS image is also much faster than this software.
    I know downloading multiple files is slower than downloading a single file, if their size are same.
    But the downloading of multiple files in OSD is "really" very slow.
    Why?  Cause of BITS or RDC?  How to fix it?
    PS:I update to SCCM 2012 R2 with CU1,  add the below into SCCM
    Windows Registry Editor Version 5.00
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\SMS\DP]
    "RamDiskTFTPBlockSize"=dword:00004000
    http://windowsdeployments.net/how-to-speed-up-pxe-boot-in-wds-and-sccm/
    Now, the download speed up to 4 minutes, but it still slower than the normal copy & paste. 
    Test result:
    OSD: 2.6G
    single image, 2 minutes
    OSD: 750m multiple files, 4 mintues
    after OSD, copy & paste from network drive, 750 multiple files, 1 mintue

    I had updated to CU1 and add this into regedit . It is quicker than before, but it still slower than the normal.
    Windows Registry Editor Version 5.00
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\SMS\DP]
    "RamDiskTFTPBlockSize"=dword:00004000
    http://windowsdeployments.net/how-to-speed-up-pxe-boot-in-wds-and-sccm/
    Download 2.63 G OS image:
    2min
    Download 750 M multiple
    files 4min

  • How can I download multiple files simultaneously? e.g. 6 files

    When I attempt to download multiple files (say 5 in number), the Mozilla allows only two files too be downloaded simultaneously. I wanted to change the option of downloading six files together but did not find the feature that could do so. Can you please kindly help or there is no such feature in Mozilla?

    There is a hidden preference for this. Check out this article: [http://kb.mozillazine.org/Network.http.max-persistent-connections-per-server Network.http.max-persistent-connections-per-server - MozillaZine Knowledge Base]
    If you haven't changed Firefox settings through about:config before, I recommend backing up your Firefox settings in case something goes wrong. See [https://support.mozilla.com/en-US/kb/Backing+up+your+information Backing up your information]. (You can copy your entire Firefox profile folder somewhere outside of the Mozilla folder.)

  • How to download multiple files from Creative Cloud

    I uploaded about 30 photos to creative cloud storage. Now I cannot find a way to download a group or all at the same time. You can select multiples and move to different folders within CC, but can't download multiples. Had I known this before using it, I would have made a zip folder of images. It seems a bit clunky if this is true.

    [email protected]
    Thanks for the info. As a professional user, more functionality in the storage would be helpful. Right now I'm using other file transfer and storage soulutions that are far superior.
    I think most Cloud users would very much agree with you.
    The Cloud today is a reasonable version 1 product but it's clunky, lacks fundamental features and is a latecomer to a rapidly maturing market. Other offerings currently shine in comparison.
    Our expectations as consumers are very high because we're used to the Dropboxes (and other superior 3rd party solutions) out there.
    Adobe has been inundated with feature suggestions and enhancements from users. The more, the better.
    They might, as they claim, be working on improvements but they've got to get a move on before the Cloud tarnishes its own reputation too much due to lack of (expected) features.
    [email protected] wrote:
    By the way, the links in your post did not lead anywhere.
    The Jive forum software used by Adobe is creating bad links.
    Correct links are:
    Three things I'd like to see...
    http://forums.adobe.com/ideas/1789
    Three ideas: folder sharing, branded channel, e-mail notification
    http://forums.adobe.com/ideas/1706
    Share folders and branded channel?
    http://forums.adobe.com/ideas/1701

  • Downloading multiple files from a site with single request?

    Interesting Scenario:
    User clicks on check boxes indicating which files they want to download from a site, then clicks a "Download" button. Is there a way (other than ZIPPING them) to download each file individually to the directory they specify?
    We have a reason for wanting individual files, instead of one lumped ZIP.
    We use Java for our appserver and JSPs for our pages.

    User clicks on check boxes indicating which files
    they want to download from a site, then clicks a
    "Download" button. Is there a way (other than
    ZIPPING them) to download each file individually to
    the directory they specify?I would think the answer is "no", since HTTP is request, response (1 response) and don't know how you'd get that one response to be "here are 2 files for the user to save to one directory".

  • Trouble converting downloaded m4a files to mp3 format

    This has never happened to me before. I downloaded a full album and 3 of the 13 songs get an error saying "the file format is not valid" when I try to convert the files to mp3 format. How do I go about fixing this?

    +if I do that, it will create the MP3 files all in the same iTunes Music folder as the AAC files,+
    Yes, if the AACs are by artist/album
    +and worse, it will probably duplicate each song in the playlist.+
    No, the conversion process does not touch any playlists.
    +The only thing I can think of is to either (A) have a blowaway copy of iTunes on the Windows PC, copy all the AAC files to it, import them, and convert them, or (B) allow my real iTunes to duplicate them all, make the MP3 CDs, sort by create date or file type, and delete the MP3 duplicates from the library.+
    B sounds easier than A. You can also consider doing the conversions with a non-iTunes program such as Switch, which allows you to specify the destination folder for the new file.

Maybe you are looking for