java file for downloading anykind of resource from the server

Hi folks...

Can anybody tell me how to write a java program which can download any kind of file ( be it a text file, exe file, sound file or whatever) from the server. I have a java program which downloads text/ exe files from my PWS, but when i try 2 open it, then it says "Not a valid win32 Application(in case of exe). The text file which gets downloaded from that app. does not contatin any text in that.

If somebody wants that code (which i have) then i will post it on this forum. It will be my gr8 favour if anybody can help me out.

Thanx in advance

Jameel

[601 byte] By [jameel_khan78] at [2007-9-26 2:30:11]
# 1
I think indeed you will get better response for your question if you post your code - or at least a part of it (meaning of course the part which is responsible for the actual transfer). Make sure you do a binary transfer.
leukbr at 2007-6-29 9:48:39 > top of Java-index,Archived Forums,Java Programming...
# 2
Sounds like you're not closing the file when done. This is probably leaving a 0 size file on your operating system. Make sure you correctly close the FileInputStream or whatever.
schillj at 2007-6-29 9:48:39 > top of Java-index,Archived Forums,Java Programming...
# 3

String fname=req.getParameter("fname");

String folder1=req.getParameter("folder");

String folder=folder1+"/"+fname+".pdf";

res.setContentType("application/pdf");

res.setHeader("Content-Disposition","attachment;filename="+fname+".pdf;");

ServletOutputStream stream = res.getOutputStream();

BufferedInputStream fif =

new BufferedInputStream(new FileInputStream(folder));

int data;

while((data = fif.read()) != -1) {

stream.write(data);

}PrintWriter out = res.getWriter();

fif.close();

stream.close();

priviet at 2007-6-29 9:48:39 > top of Java-index,Archived Forums,Java Programming...