/**远程文件下载
* @param remoteFilePath 下载地址
* @param response
* @author DanaHe
*/
public static void downloadFile(String remoteFilePath,HttpServletResponse response) {
URL urlfile = null;
HttpURLConnection httpUrl = null;
BufferedInputStream bis = null;
ServletOutputStream bos = null;
try
{
urlfile = new URL(remoteFilePath);
httpUrl = (HttpURLConnection)urlfile.openConnection();
httpUrl.connect();
bis = new BufferedInputStream(httpUrl.getInputStream());
bos = response.getOutputStream();
int len = 2048;
byte[] b = new byte[len];
while ((len = bis.read(b)) != -1)
{
bos.write(b, 0, len);
}
bos.flush();
bis.close();
httpUrl.disconnect();
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
try
{
bis.close();
bos.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
java 远程文件 下载
最新推荐文章于 2024-08-11 03:51:41 发布