maven引入公共组件,使用里面的一个复制文件的工具类
<!--公共组件类-->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
获取图片,爬虫不细说,用其他爬虫框架也可以,url和User_Agent为变量参数
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpGet httpget = new HttpGet(url);
httpget.addHeader("User-Agent", User_Agent);
CloseableHttpResponse response = null;
try {
response = httpClient.execute(httpget);
HttpEntity entity = response.getEntity();
InputStream inputStream = entity.getContent();
FileUtils.copyToFile(inputStream, new File("E:\\a.jpg"));
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
httpClient.close();
response.close();
} catch (IOException e) {
e.printStackTrace();
}
}