//downFileUrl 遠程文件下載地址
public void downFile(String downFileUrl) throws Exception {
try {
String fileName = downFileUrl.substring(downFileUrl.lastIndexOf("/") + 1); //取文件名
String savePath = "D:/wwwroot/"+ fileName; //要另存的路徑+文件名作為路徑
URL downUrl = new URL(downFileUrl);
URLConnection conn = downUrl.openConnection();
int dataSize = conn.getContentLength(); //取得要下載的數據的長度
BufferedInputStream in = new BufferedInputStream(conn.getInputStream());
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(new File(savePath)));
byte[] data = new byte[1024];
int len = in.read(data);
while (len != -1) {
out.write(data, 0, len);
len = in.read(data);
}
in.close();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}