国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設(shè)計 > 正文

網(wǎng)絡(luò)圖片地址轉(zhuǎn)為字節(jié)流

2019-11-06 06:17:25
字體:
供稿:網(wǎng)友
public class GetByteByNetUrl {        /**       * 根據(jù)地址獲得數(shù)據(jù)的字節(jié)流       * @param strUrl 網(wǎng)絡(luò)連接地址       * @return       */        public static byte[] getImageFromNetByUrl(String strUrl){            try {                URL url = new URL(strUrl);                HttpURLConnection conn = (HttpURLConnection)url.openConnection();                conn.setRequestMethod("GET");                conn.setConnectTimeout(5 * 1000);                InputStream inStream = conn.getInputStream();//通過輸入流獲取圖片數(shù)據(jù)                byte[] btImg = readInputStream(inStream);//得到圖片的二進制數(shù)據(jù)                return btImg;            } catch (Exception e) {                e.PRintStackTrace();            }            return null;        }        /**       * 從輸入流中獲取數(shù)據(jù)       * @param inStream 輸入流       * @return       * @throws Exception       */        public static byte[] readInputStream(InputStream inStream) throws Exception{            ByteArrayOutputStream outStream = new ByteArrayOutputStream();            byte[] buffer = new byte[1024];            int len = 0;            while( (len=inStream.read(buffer)) != -1 ){                outStream.write(buffer, 0, len);            }            inStream.close();            return outStream.toByteArray();        }    
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 从江县| 葵青区| 正宁县| 江门市| 韶山市| 孟津县| 湖口县| 阜平县| 常宁市| 高雄县| 萝北县| 邵武市| 新化县| 尉氏县| 佳木斯市| 黄冈市| 织金县| 和硕县| 汨罗市| 微山县| 航空| 宜城市| 金秀| 绥芬河市| 西林县| 贺兰县| 日照市| 石家庄市| 浦北县| 郯城县| 武城县| 云和县| 石楼县| 皮山县| 吉首市| 合水县| 江源县| 东方市| 宽城| 琼中| 灵寿县|