将网络url图片链接转换为File类型对象
生活随笔
收集整理的這篇文章主要介紹了
将网络url图片链接转换为File类型对象
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
將網絡url圖片鏈接轉換為File類型對象
public static File convertFileByUrl(String url) {File file = null;URL urlfile;InputStream inputStream = null;OutputStream outputStream= null;try {file = File.createTempFile("wx_image", ".png");//下載urlfile = new URL(url);inputStream = urlfile.openStream();outputStream= new FileOutputStream(file);int bytesRead = 0;byte[] buffer = new byte[8192];while ((bytesRead = inputStream.read(buffer, 0, 8192)) != -1) {outputStream.write(buffer, 0, bytesRead);}} catch (Exception e) {e.printStackTrace();} finally {try {if (null != outputStream) {outputStream.close();}if (null != inputStream) {inputStream.close();}} catch (Exception e) {e.printStackTrace();}}return file;}總結
以上是生活随笔為你收集整理的将网络url图片链接转换为File类型对象的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: notion 科研_科研新手全面入坑指南
- 下一篇: 自动驾驶之高精地图