public static String Settext(String urlstr) { try { URL url = new URL(urlstr); HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); int responseCode = urlConnection.getResponseCode(); if (responseCode == 200) { InputStream inputStream = urlConnection.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(inputStream)); String lin = ""; StringBuilder sb = new StringBuilder(); while ((lin = br.readLine()) != null) { sb.append(lin); } return sb.toString(); } else { //Toast.makeText(this,"当前网络不可用",Toast.LENGTH_LONG).show(); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return ""; } public static Bitmap Setimg(String urlstr) { URL url = null; try { url = new URL(urlstr); HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); int responseCode = urlConnection.getResponseCode(); if (responseCode == 200) { InputStream inputStream = urlConnection.getInputStream(); Bitmap bitmap = BitmapFactory.decodeStream(inputStream); return bitmap; } else { } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
获取文件和图片的方法
最新推荐文章于 2021-09-08 17:30:36 发布