Télécharger une image et l’enregistrer sur le disque local

Author:


{filelink=846}

        //Télécharger une image et l'enrefistrer sur le disque dur
        public static void saveImage(String imageUrl, String destinationFile) throws IOException {
		URL url = new URL(imageUrl);
		InputStream is = url.openStream();
		OutputStream os = new FileOutputStream(destinationFile);

		byte[] b = new byte[2048];
		int length;

		while ((length = is.read(b)) != -1) {
			os.write(b, 0, length);
		}

		is.close();
		os.close();
	}

Leave a Reply

Your email address will not be published. Required fields are marked *