Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

How to download a word document from net?

Hi,

I have written the following program to download a file from net. Its is downloading the document if it is a direct link (The link given in the below Java program or any html page).

But if i try the same for an asp page its not working. The asp page link is something like the below: (this page will open a word document in internet browser)

http://xxxx/xxxx/xx.asp?User=Ser&id=005

But the java program is not downloading the document from the above link.

If I just give the link as
http://xxxx/xxxx/xx.asp
it downloads that asp page. It seems this program is not passsing the inputs (the values after '?' character given in the link) for that asp page and because of that the word document is not downloaded. Could you please help me out in solving the issue?

import java.io.*;
import java.net.*;
public class Filetrans {
public static void main(String args[])
{
try{
URL url = new URL("http://www.nydic.org/nydic/documents/FinalCompetencies1.doc");
URLConnection connection = url.openConnection();
connection.getPermission();
InputStream stream = connection.getInputStream();
BufferedInputStream in = new BufferedInputStream(stream);
FileOutputStream file = new FileOutputStream("C:\\temp\\final.doc");
BufferedOutputStream out = new BufferedOutputStream(file);
int i;
while ((i = in.read()) != -1) {
out.write(i);
}
out.flush();
}
catch(Exception e)
{
System.out.println("Exception" + e);
}
}
}

Regards,
Jayaprabhu.M
[1607 byte] By [Jayaprabhu_m] at [2007-11-11 8:17:26]