SHARE
TWEET

Untitled

a guest Oct 14th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     public static void saveImage(String imageUrl) throws IOException {
  2.         String tempDir = System.getProperty("java.io.tmpdir");
  3.         URL u = new URL(imageUrl);
  4.         String fileName = u.getFile();
  5.         String destName = tempDir + fileName.substring(fileName.lastIndexOf("_"));
  6.         System.out.println(destName);
  7.         HttpURLConnection i = (HttpURLConnection) u.openConnection();
  8.         i.setRequestProperty("Connection", "close");
  9.         InputStream is = i.getInputStream();
  10.         OutputStream os = new FileOutputStream(destName);
  11.  
  12.         byte[] b = new byte[2048];
  13.         int length;
  14.  
  15.         while ((length = is.read(b)) != -1) {
  16.             os.write(b, 0, length);
  17.         }
  18.         is.close();
  19.         os.close();
  20.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top