| | |
| | | import java.awt.*; |
| | | import java.awt.image.BufferedImage; |
| | | import java.io.*; |
| | | import java.net.HttpURLConnection; |
| | | import java.net.MalformedURLException; |
| | | import java.net.URL; |
| | | import java.util.ArrayList; |
| | |
| | | URL url = null; |
| | | int imageNumber = 0; |
| | | try { |
| | | url = new URL(imgUrl); |
| | | DataInputStream dataInputStream = new DataInputStream(url.openStream()); |
| | | |
| | | InputStream inputStream = null; |
| | | HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(imgUrl).openConnection(); |
| | | httpURLConnection.setRequestMethod("GET"); |
| | | httpURLConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36"); |
| | | httpURLConnection.setRequestProperty("Accept-Encoding", "gzip"); |
| | | httpURLConnection.setRequestProperty("Referer","no-referrer"); |
| | | httpURLConnection.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); |
| | | httpURLConnection.setConnectTimeout(15000); |
| | | httpURLConnection.setReadTimeout(20000); |
| | | inputStream = httpURLConnection.getInputStream(); |
| | | |
| | | |
| | | |
| | | FileOutputStream fileOutputStream = new FileOutputStream(new File(savePath)); |
| | | ByteArrayOutputStream output = new ByteArrayOutputStream(); |
| | | byte[] buffer = new byte[1024]; |
| | | int length; |
| | | while ((length = dataInputStream.read(buffer)) > 0) { |
| | | while ((length = inputStream.read(buffer)) > 0) { |
| | | output.write(buffer, 0, length); |
| | | } |
| | | byte[] context=output.toByteArray(); |
| | | fileOutputStream.write(output.toByteArray()); |
| | | dataInputStream.close(); |
| | | inputStream.close(); |
| | | fileOutputStream.close(); |
| | | } catch (MalformedURLException e) { |
| | | e.printStackTrace(); |