Solved

setHeader method in JAVA

Posted on 2000-02-18
5
352 Views
Last Modified: 2012-08-13
How can I add the size of the file to my headers so that people downloading my .rtf files will know how large the files are?

the following code is what I have so far:

setHeader("Content-disposition", "attachment;filename=" + reportType + ".rtf");

is adding  ";filesize=" + filename.size() even close to an answer?

0
Comment
Question by:jerelw
  • 3
  • 2
5 Comments
 
LVL 5

Accepted Solution

by:
mbormann earned 100 total points
ID: 2536636
I think it's Content-Length, I think that before you write anything to the stream,set it with the correct Length you are going to write.

Note that thsi is the way of specifying persistemt connections (also called as Keep Alive)

Read for basics
http://www-4.ibm.com/software/webservers/appserv/doc/v20dcadv/doc/readme.txt

code
http://www.servletforum.com/sf/1999/Nov/941724512594.html
0
 
LVL 3

Author Comment

by:jerelw
ID: 2538553
i'll try it, for a bonus, how do i get the file size if the report is created at runtime?
0
 
LVL 5

Expert Comment

by:mbormann
ID: 2541249
was away on leave ,but the file size is always got at runtime.I don't understand what you mean to say.
0
 
LVL 3

Author Comment

by:jerelw
ID: 2542445
is there a method called getSize() that would return an int of my file in bytes?

for example,

File f = new File("myFile");
int size = f.getSize();

and then in my header I can specify my file size by entering:

content-length: size }
0
 
LVL 5

Expert Comment

by:mbormann
ID: 2542480
int size = (int)f.length();
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to implement Singleton Design Pattern in Java.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question