Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...These forums are an excellent source and example of the way people can help each other..."

Geography

Where in the world do Tek-Tips members come from?
MoreFeo (TechnicalUser)
8 Jan 08 11:39
Hi, I'm trying to follow thread thread695-824677: "Save As" dialog box instructions, and it seems to work ok, except that the file created is 20 kB bigger than the original, and that files that are not plain text (like .doc or .zip) can't be opened.

Does anyone know what can cause this?

Thanks
MoreFeo (TechnicalUser)
9 Jan 08 5:28
Sorry, it's not 20kB, it's 20 bytes that it adds, I think at the begining of the file.

Here is the code I've tried:

CODE

<netui-data:getData resultId="path" value="{pageFlow.filePath}" />
<netui-data:getData resultId="name" value="{pageFlow.fileName}" />
<%
    String path = (String)pageContext.getAttribute("path");
    String name = (String)pageContext.getAttribute("name");
    
    response.setContentType("application/octet-stream");
    response.setHeader("Content-disposition", "attachment;filename="+name);
    
    File myFile = new File(path);
    OutputStream o = response.getOutputStream();
    
    FileInputStream fis = new FileInputStream(myFile);
    int i = fis.available();
    System.out.println("fis.available: " + i);
    int iRead;
    int iLength = 0;
    while ((iRead=fis.read())!=-1)
    {
        o.write(iRead);
        iLength++;
    }
    System.out.println("iLength: " + iLength);
    fis.close();
    o.flush();
    o.close();
%>

When I execute this, both fis.available and iLength give the current size of the file, but the file created is 20 bytes bigger and is corrupt.

If I try this with a plain text file, I can see that it adds 10 blank lines at the begining of the file.

Does anyone know how to fix this?

Thanks.
MoreFeo (TechnicalUser)
9 Jan 08 18:57
Well, I got it.

I was doing it in a JSP page, but it must be done from a servlet, because JSPs write more code than you want (each <%@ import inserts a blank line).
prosper (Programmer)
13 Jan 08 22:28
It seems that you use weblogic server

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close