Solved

setHeader method in JAVA

Posted on 2000-02-18
5
365 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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 …
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

717 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