Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void saveImage(String imageUrl) throws IOException {
- String tempDir = System.getProperty("java.io.tmpdir");
- URL u = new URL(imageUrl);
- String fileName = u.getFile();
- String destName = tempDir + fileName.substring(fileName.lastIndexOf("_"));
- System.out.println(destName);
- HttpURLConnection i = (HttpURLConnection) u.openConnection();
- i.setRequestProperty("Connection", "close");
- InputStream is = i.getInputStream();
- OutputStream os = new FileOutputStream(destName);
- byte[] b = new byte[2048];
- int length;
- while ((length = is.read(b)) != -1) {
- os.write(b, 0, length);
- }
- is.close();
- os.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement