public static void main(String[] args) throws IOException
{
try
{
// hasActive();
HttpClient client = new HttpClient();
GetMethod get = new GetMethod("http://a.jpg");
int i = client.executeMethod(get);
if (200 == i)
{
File storeFile = new File("c:/bb.gif");
FileOutputStream output = new FileOutputStream(storeFile);
// 得到网络资源的字节数组,并写入文件
output.write(get.getResponseBody());
output.close();
}else
{
System.out.println("no pic");
}
} catch ( Exception e )
{
System.out.println("no pic");
}
}
本文提供了一个使用Java进行网络图片下载的简单示例代码。通过HttpClient和HttpGet方法从指定URL获取图片,并将其保存到本地文件系统中。该示例展示了如何处理HTTP请求及响应,同时介绍了基本的错误处理。
1018

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



