Solved

setHeader method in JAVA

Posted on 2000-02-18
5
327 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now