Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2009
    Posts
    28
    Rep Power
    0

    Default How to download a file from directrory

    After clicking the hyperlink, a file from directory has to be downloaded.control has come to Controller while debugging but file is not downloading.How to write for this?
    Java Code:
    File dir = new File(request.getRealPath("/")+"uploads/"+bugId);
    try {
    
    response.setContentType("APPLICATION/DOWNLOAD");
    response.setHeader("Content-Disposition", "attachment"+"filename=\""+fileName+"\"");
    FileInputStream stream = new FileInputStream(dir+"/"+fileName);  
    response.setContentLength(stream.available());
    
    os = response.getOutputStream();
    os.close();
    response.flushBuffer(); 
    
    }catch(Exception e) {
    e.printStackTrace();
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,244
    Rep Power
    19

    Default Re: How to download a file from directrory

    Moved from Advanced Java

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,015
    Rep Power
    20

    Default Re: How to download a file from directrory

    Where in that code are you writing to the output stream?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 0
    Last Post: 03-05-2010, 04:21 AM
  2. Download file from URL?
    By makpandian in forum Networking
    Replies: 0
    Last Post: 03-10-2009, 12:31 PM
  3. Download file from URL?
    By makpandian in forum New To Java
    Replies: 0
    Last Post: 03-10-2009, 12:30 PM
  4. File Download
    By AnGuRuSO in forum New To Java
    Replies: 9
    Last Post: 10-29-2008, 11:00 AM
  5. file download
    By abhiN in forum New To Java
    Replies: 0
    Last Post: 02-08-2008, 09:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •