private boolean checkNetwork() { ConnectivityManager connManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); if (connManager.getActiveNetworkInfo() != null) { return connManager.getActiveNetworkInfo().isAvailable(); } return false; }
// 将输入流转化为 String 型 private static String parseInfo(InputStream inStream) throws Exception { byte[] data = read(inStream); // 转化为字符串 return new String(data, "UTF-8"); } // 将输入流转化为byte型 public static byte[] read(InputStream inStream) throws Exception { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while ((len = inStream.read(buffer)) != -1) { outputStream.write(buffer, 0, len); } inStream.close(); return outputStream.toByteArray(); }
时间: 2024-10-29 19:07:23