Downloading File/Save Problem....Help!!!!

Hello All,
I have written a code to download a Text file from Server to Local Disk.But the problem
is that when i click a Button in the JSP page through which the downloading of file is
done,opens a Dialouge Box with the "Save To Disk " option selected.when i go for the Save
option the Text Field shows me a Wrong Filename("downloadFile.htm")....which is not the
File i want Download.I want to Download "1003-3.txt"....
Also when i go for the "OPEN" option and click on "OK" the Dialouge Box Opens again
with the "Save To Disk" option selected,when i click on "OK" the Text Field of the
Dialouge Box Shows the CORRECT Filename("1003-3.txt").....when i click OK the File
gets DOWNLOADED but with "NO CONTENTS".....
The snippet of code is .....
public HttpServletResponse doDownloadFile(HttpServletRequest req,HttpServletResponse res)
          throws ServletException,IOException {
          String fname = "1003-3.txt";
          res.setContentType("application/binary");
          res.setHeader("Content-Disposition","attachment; filename=\""+fname+"\";");
          ServletOutputStream stream = null;
          try {
               stream = res.getOutputStream();
               BufferedInputStream bif = new BufferedInputStream(new FileInputStream(fname));
               int data;
               while(( data = bif.read()) != -1) {
                    stream.write(data);
                    stream.flush();                    
               bif.close();
               stream.close();
               return res;
               } catch(Exception e) {
               finally {
               if (stream != null)
               stream.close();
               return res;
Can Anybody Help me out with the problem....Please it is URGENT!!!!!!
Thanks a MILLION in Advance

Hello All,
I am using the Code,as below, to Download a Text File from a particular
Directory on the Server to any where the user need to download it through the Dialouge box...
But what i Really want to achieve is that the user should not be asked for an Dialouge box, instead it
should Download the Text file directly to "Desktop"(By Default)...
Is there a way to do so...if yes can anybody help me out with the solution...
<Code>
public HttpServletResponse doDownloadFile(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException {
ServletOutputStream stream = null;          
res.setContentType("application/binary");
String fname1 = req.getParameter("BusinessId");
String fname2 = req.getParameter("AccountUserId");
String fname =fname1+"-"+fname2+".txt";
res.setHeader("Content-Disposition","inline; filename=\""+fname+"\";");
BufferedInputStream bif = null;          
try {
bif = new BufferedInputStream(new FileInputStream("C:/ABCD/download/XYZ/"+fname));               
stream = res.getOutputStream();
byte [] buf = new byte[20480];
int data;
while(( data = bif.read(buf,0,20480)) != -1) {
stream.write(buf, 0, data);
stream.flush();                    
bif.close();
stream.close();               
return res;
} catch(Exception e) {
System.out.println("The Exception in MainServlet is :"+e);
finally {
if (stream != null)
stream.close();
return res;
}//end of method
</Code>
Thanks a million in advance,
Regards
Sam

Similar Messages

  • Hi I am trying to download the family tree maker that i purchased by email onto my ipad however I keep getting the same thing SAFARI CANNOT DOWNLOAD FILE can anyone help me solve this problem thanks.....bebe

    Hi i am i have any ipad and i am trying to download family tree maker that i purchased online, but all that keeps co ing up is safari cannot download file can anyone help me .....bebe

    I think you are trying to install a computer application to use on an iPad. You can't. They are incompatible pieces of hardware. If you want Family Tree Maker for your iPad, then you need to get that version, if it exists, from the iTunes Store. That download can't be done via Safari.

  • PDF 'File Save' problem in Firefox

    Using Firefox browser, when I select a PDF file that opens in a new window [rather than a new tab], save it and close the window, the AcroRD32.exe process is not stopped.  If I then open another PDF file in a similar manner, it can not be saved.  Each time you close a PDF window, you have to go to Task Manager and stop the AcroRD32 process before being abl;e to save a subsequent document.  This does not happen with IE.
    Using Reader 10.1.1 and Firefox 8 on a Windows Vista32 system.

    Same bug i see in Opera browser. PDFs doesn't saves without stopping AcroRd32 process. And save dialogue doesn't appears when clicking links (even if web browsing function deactivated in adobe reader settings)...
    Apart from this File Save problem, there is more strange things while browsing PDF online, like "blinks", hangs, image dissapear, suddenly lags without any reason, browser crashing and more...
    So, because adobe reader prevents to download PDFs, and because it works very buggy with online browsing, especially if website uses adobe flash to show PDFs, the only right solution i found is uninstalling adobe reader. After that File Save problem was gone!

  • Download file servlet problem

    hello
    i have a file stored in a byte[] form now i am using a servlet call for a link it works fine
    i get byte[] from database no i want that instead of making a file i can use this byte[] for the user as a file
    in short i have a link which calls a servlet it get byte[] from database how can i use this for user to get file as download file with out writing to server as file i just want these bytes to flush out??
    advance thanks
    Shakeel abbas

    thanks BALUSC
    the problem is solved as
    ServletOutputStream op = response.getOutputStream();
                        int length = 0;
                        byte[] bbuf = new byte[invoice.getInvoiceFile().length];
                        ByteArrayInputStream arrayInputStream = new ByteArrayInputStream(invoice.getInvoiceFile());
                        DataInputStream in = new DataInputStream(arrayInputStream);
                        while ((in != null) && ((length = in.read(bbuf)) != -1)) {
                             op.write(bbuf, 0, length);
                        }

  • Rcu download file unavailable..help me in downloading for win64 bit os

    help needed in downloading rcu for soa suite..
    I want to download rcu generic.jar file for windows 64 bit operating system.
    But here under generic tab there is no rcu file to download...
    where as rcu download file for 32 bit is available..
    http://www.oracle.com/technetwork/middleware/soasuite/downloads/index.html
    help ...
    Edited by: 971317 on Nov 14, 2012 4:19 PM

    Your configuration looks ok for me... Have a look at the Oracle Fusion Middleware Supported System Configurations and check the certification matrix... Open a SR with Oracle Support and ask them, maybe there are some known issues with your configuration...
    http://www.oracle.com/technetwork/middleware/ias/downloads/fusion-certification-100350.html

  • ECL Viewer 7.0 patch 3 DXN file font problem  HELP ME!!!!!!!!

    Hi everyone!
    During display og .DXN files in ECL Viewer the problem window pops up
    The problem is that program does not see  isocp.shx and simplex.shx files
    These files holds font data for CAD files
    I downloaded these files from internet
    The question is
    How to instal it to be visible for ECL Viewer??
    I got also another problem
    ECL Viewer does not hold user settings for colors
    can somebody help me these issues??
    All Best
    Damian Radomski

    Hi Damian,
    As a solution you can think of  the possibility to use an external DXN Viewer. Therefore you have to maintain the parameter %AUTO% in transaction DC30 for you DXN Workstation application. This parameter will call the external viewer
    which is maintained in the Windows folder options for format DXN.
    ECL Viewer does not hold user settings for colors
    Please explain this issue in detail
    Regards,
    Deepak Kori

  • Lightromm 2.4 + Photoshop CS3 + NAS file save problems

    I'm not sure if this has been asked before (I couldn't find it when I looked...) but I have the following problem.
    I have a folder of JPG files on a NAS drive ( I'm using a Mac OSX 10.5.7 )
    When I have Lightroom open I can't then edit and save the images. I have tried opening them from within Lightroom and get a file may be in use error when I try and save it. I have tried opening them via finder with CS3 and get the same error when I try and save them. If I then close lightroom it all works fine.
    If I open a raw file from within Lightroom (also on the NAS) and save it Lightroom creates a PSD file (as i have asked it to do) and saves it without a problem. If I then go back to re-edit the PSD file and save it I get the same file may be in use error and can't save my changes. Again, if I close Lightroom I can then edit and save the file without a problem.
    For some reason it looks as though lightroom locks all the files in the catalog that are stored on the NAS even when they are not being edited......
    Any help gratefully received  !!

    It'll be no surprise to you to learn that LR isn't designed to work on networks. AFAIK, the workaround is as you've found: Quit LR, and the .lock is removed. I suppose you could delete the .lock file and keep LR open, but I can't recommend that.

  • File Save Problem

    Hi Experts,
    I am using MAC OSX 10.8.3
    My script is :
    #target indesign
    var myDocument=app.activeDocument;
    myDocument.save(File("/var/Untitled-1.indd"));
    It give error
    can not save "Untitled-1.indd" under a new name
    While this script run successfully on MAC OSX 10.6.8
    How save this file under a new name ?
    I also give permission to  /Var/
    using  sudo chmod -R 777 '/Var/'
    Login from User ID in MAC OSX
    Not System Administrator
    Thanks.

    While most file managers are not fussy about the cases used in File names, JavaScript is: could it be that your problem is caused by the difference between "var" and "Var"? Just guessing.
    Dave

  • Photoshop file save problems?

    As i complete a project, i go to save my work and when i get to the save window and try to select the format that i want to save in, i can only save in Photoshop editable file formats and cannot for example save in '.PNG' ect? Please Help!!

    Nobody can tell you anything without proper system info or other technical details liek what version of PS or your document. Available formats can depend on several things like color mode, document size and so on.
    Mylenium

  • Downloading new itunes problem HELP !

    When i go to download iTunes 7.5 it goes through the download proccess and an error popup that says " This installation package could not be opened. Verify that the package exists and that you can access it, or contact the application vendor to verify that this is a valid Windows Installer package. " comes up . HELP !

    Hi MarRedd!
    Here is an article that will help you troubleshoot this issue:
    iTunes 11.1.4 for Windows: Unable to install or open
    http://support.apple.com/kb/TS5376
    Thanks for being a part of the Apple Support Communities!
    Cheers,
    Braden

  • Executing .sql file, path problem,help!

    Hi, could anyone tell me that how to change the default .sql file running path in Oracle 8?
    I am running Oracle 8 resides on IBM AIX server. i found that under SQL prompt, the default .sql file running path is my home directory,e.g./home/user01,so i have to save all .sql files under that directory....could anyone tell me how to modify the default path to other directories.e.g,/home/user01/sql, so i could collect all .sql files under a specified directory?
    Many thanks

    Set the environment variable SQLPATH
    For more information see
    SQLPATH on 9iRel2 on Win XP

  • AL11 File Save Problem

    Good morning everybody,
    I've again ran into a problem using AL11. While exporting my file unconverted I seem to be losing white space.
    I'm writing an ecryption program that operates using ASCII Characters 32 to 126, spaces included.
    1) After program execution, the white space character is in the string at the end
    [http://imgur.com/MvXRU]
    2) When I export to HTML format, it appears that the white space is still there
    [http://i.imgur.com/CBemx.jpg]
    3) When I export uncoverted to text file, the white space is removed.
    [http://i.imgur.com/TELSx.jpg]
    The text file on the application server is then transferred using a windows batch file to another location where it can be decrypted using a key. However, the problem is that since whitespace at the end is shaved, It kind of ruins the decryption and message.
    I'm thinking that the space is still there on the text file that is on the application server because the space is exported when going to HTML, but I can't access the file directly, only this way which.
    So, my question being is white-space at the end of lines trimmed upon export from AL11? Is there a way to avoid this?

    Hi Suhas,
    Sure. I can't do a fixed length because the lines vary. Some lines are 20 characters, others are 300. Also if I use a fixed length and the extra spaces get added to other lines then I have an alignment problem.
        open dataset ls_c_path for output in text mode encoding non-unicode.
        do li_bp_str_length times.
          lc_key = me->cl_keygen->get_current_key( ).
          lc_dec = ls_cur_bp_str+li_str_pos(1).
          lc_enc = me->cl_v->enc_char( in_key   = lc_key
                                              in_char  = lc_dec
                                              in_pos   = li_str_pos
                                              in_l_num = li_line_number ).
            concatenate ls_text_line lc_enc into ls_text_line respecting blanks.
          clear lc_enc.
          li_str_pos = li_str_pos + 1.
        enddo.
        transfer ls_text_line to ls_c_path.
    Even with the transfer statement given a length, the space at the end still gets cut off.
    transfer ls_text_line to ls_c_path length li_bp_str_length.
    Edited by: Bryan Abrams on Jun 8, 2011 10:05 AM
    Edited by: Bryan Abrams on Jun 8, 2011 10:07 AM
    Edited by: Bryan Abrams on Jun 8, 2011 10:23 AM

  • Downloading file on S3 - help!

    I downloaded a PDF file from email yesterday - viewed it and then went into my downloads and deleted the file. Well, my phone is still showing an arrow like the file is still be downloaded. I've restarted my phone, taken the battery out....nothing is making this icon go away! How do I get it to go away??

    I've had this happen on both Android phones that I have owned. I think you have to open the browser you used for the download, then press menu>downloads, and clear it there. Of course, that's only if I remembered correctly.

  • I downloaded a video from a piano site I can not find the downloaded file/ video please help me

    I Downloaded a video from a piano site can not locate where the video is please help me

    You will need to download a third party app in order to play Movies that are not from the iTunes Store or synced from your computer. I know absolutely nothing about any of these, so you will have to do your own research.
    http://appadvice.com/appguides/show/alternative-video-players

  • Illustrator CS4 file save problem

    Recently, when I try to save an Illustrator file to a server or locally, instead of replacing the file, it shows this dialog and creates a duplicate with a "1" appended. Any ideas?

    Ah, thank you! I never thought of that since I only have 1 artboard.
    But I saved again under a different name and made sure it was unchecked. It worked!

Maybe you are looking for