File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes unable to download xml file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "unable to download xml file" Watch "unable to download xml file" New topic

unable to download xml file

Ritu Pande

Joined: Jun 05, 2005
Posts: 17
Dear All,

I m trying to download the xml file from the server. I m able to get the download dialog box and able to download the file on the client browser, the file contains the print statement given in the jsp file. Its not displaying the original content of xml file. Below is the jsp code. I m not getting where its going wrong.

<%@ page import="*,,,,,"%>
String fileName = "forma.xml";
String actualFileName = directory + fileName;
out.println("ACTUAL FILE NAME : " + actualFileName +"<BR>");
InputStream inputStream = null;
try {
response.setHeader("Content-Disposition","attachment;filename=" + fileName );
int sizeRead = 256;
byte[] buf = new byte[1024];
File file = new File(actualFileName).getAbsoluteFile();
out.println("FILE : "+file +"<BR>");
URL url = file.toURL();
inputStream = (BufferedInputStream)url.openConnection().getContent();
out.println("INPUT STREAM ......." + inputStream +"<BR>");
while( (sizeRead = != -1 ){

/*FileInputStream fileinputstream = new FileInputStream(file);
byte abyte1[];
int i = (int)file.length();
byte abyte0[] = new byte;
for(int j = 0; j < i; j +=, j, i - j));
abyte1 = abyte0;
out.println("value of abyte1 :"+abyte1); */
} catch(Exception ex) {
out.println("Exception " + ex.getMessage() +"<BR>");
} finally{
}catch(Exception e){
out.println("Exception in finally" + e.getMessage() +"<BR>");

Thnx in adv.

Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8927


Ritu Pande

Joined: Jun 05, 2005
Posts: 17
dear pradip,

thnx a lot for the reply. but its not working.

I agree. Here's the link:
subject: unable to download xml file
It's not a secret anymore!