Package com.xxxx.service;
Import Java.io.BufferedInputStream;
Import Java.io.FileOutputStream;
Import java.io.IOException;
Import java.net.HttpURLConnection;
Import Java.net.URL;
/**
*
* Java access URL and download files
* To access the analysis system from the General Management Center and get the analysis report;
* @author XXX 2015-01-19
*
*/
public class Testsampleanalysisreport {
public static void SaveToFile (String desturl, String fileName)
Throws IOException {
FileOutputStream fos = null;
Bufferedinputstream bis = null;
HttpURLConnection httpurl = null;
URL url = null;
byte[] buf = new byte[1024];
int size = 0;
url = new URL (desturl);
Httpurl = (httpurlconnection) url.openconnection ();
Httpurl.connect ();
bis = new Bufferedinputstream (Httpurl.getinputstream ());
FOS = new FileOutputStream (fileName);
while (size = Bis.read (BUF))!=-1)
Fos.write (buf, 0, size);
Fos.close ();
Bis.close ();
Httpurl.disconnect ();
}
public static void Main (string[] args) {
try {
SYSTEM.OUT.PRINTLN ("Begin");
SaveToFile ("Http://xxxxxxx:8081/tasks/download/1", "D:\\111.doc");
System.out.println ("End");
catch (Exception e) {
E.printstacktrace ();
}
}
}