Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 382
  • Last Modified:

setHeader method in JAVA

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
jerelw
Asked:
jerelw
  • 3
  • 2
1 Solution
 
mbormannCommented:
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
 
jerelwAuthor Commented:
i'll try it, for a bonus, how do i get the file size if the report is created at runtime?
0
 
mbormannCommented:
was away on leave ,but the file size is always got at runtime.I don't understand what you mean to say.
0
 
jerelwAuthor Commented:
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
 
mbormannCommented:
int size = (int)f.length();
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now