تشارككم الأمثلة الواردة في هذه المقالة في رمز Java المحدد لحفظ الصور بناءً على عنوان الشبكة للرجوع إليه. المحتوى المحدد كما يلي
استيراد java.io.bufferedInputStream ؛ import java.io استيراد sun.misc.base64decoder ؛ /*** فئة الأدوات المشتركة* Author Hu Hansan** 2014-11-21 10:16:10 AM*/أدوات الفئة العامة "http://api.map.baidu.com/staticimage؟center=106.720568،26.585137&width=697&height=550&markers=106.729443،26.593795&mar kerstyles = -1 ، http: //api.map.baidu.com/images/marker_red.png ، -1،23،25&zoom=15&labels=106.730143،26.594695&labelstyles=bun تسوق في مجتمع معين من جامعة شيدا ، 1،14،0xffffff ، 0xec624d ، 1 "؛ الأدوات DW = أدوات جديدة () ؛ dw.savetofile (str ، "e: //"+AnguofileUtils.getRandomFilename ()+".png") ؛ } / *** احفظ الصورة وفقًا لعنوان الشبكة* param desturl عنوان الشبكة* param filepath مسار تخزين الصورة* / public void savetofile (String desturl ، String filepath) {fileOutputStream fos = null ؛ BufferedInputStream BIS = NULL ؛ httpurlConnection httpurl = null ؛ url url = null ؛ int buffer_size = 1024 ؛ byte [] buf = new byte [buffer_size] ؛ حجم int = 0 ؛ حاول {url = url new (desturl) ؛ httpurl = (httpurlConnection) url.openconnection () ؛ httpurl.connect () ؛ BIS = جديد bufferedInputStream (httpurl.getInputStream ()) ؛ fos = fileOutputStream جديد (FilePath) ؛ بينما ((size = bis.read (buf))! = -1) {fos.write (buf ، 0 ، size) ؛ } fos.flush () ؛ } catch (ioException e) {} catch (classcastException e) {} أخيرًا {try {fos.close () ؛ bis.close () ؛ httpurl.disconnect () ؛ } catch (ioException e) {} catch (nullpointerxception e) {}}}}ما سبق هو كل محتوى هذه المقالة. آمل أن يكون ذلك مفيدًا لتعلم الجميع وآمل أن يدعم الجميع wulin.com أكثر.