/**
* 获取外网物理文件
* @param filePath 存放在数据库中的文件地址,如/upload/test.jpg
* @throws Exception
*/
@SuppressWarnings("unused")
private void getFiles(String filePath) throws Exception
{
try
{
File storeFile = new File(request.getSession().getServletContext().getRealPath("")+filePath);
if (!storeFile.exists())
{
HttpClient client = new HttpClient();
GetMethod get = new GetMethod(Resources.getProperty("WAN_SITE_URL")+filePath);
client.executeMethod(get);
storeFile.createNewFile();
FileOutputStream output = new FileOutputStream(storeFile);
//得到网络资源的字节数组,并写入文件
output.write(get.getResponseBody());
output.close();
}
}
catch (Exception e)
{
e.printStackTrace();
throw new AGPException("WAN_NET_ERROR");
}
}
使用HttpClient远程抓取网页内容:http://www.cnblogs.com/modou/articles/1325569.html
从数据库获取外网物理文件
本文介绍如何通过使用HttpClient远程抓取指定URL的文件,并将其保存到服务器的指定路径。详细步骤包括创建请求、执行HTTP GET方法、读取响应体内容并写入本地文件。
170

被折叠的 条评论
为什么被折叠?



