与file_get_contents等同的方法

 public static String getUrlInfo(String url_path) {
  String result = "";
  URL url = null;
  try {
   url = new URL(url_path);
  } catch (MalformedURLException e) {
  } // 建立url连接,获取商品信息
  InputStream in = null;
  try {
   in = url.openStream();
  } catch (IOException e) {
   System.out.println("建立连接失败");
  } // 信息流
  BufferedReader breader = null;
  try {
   breader = new BufferedReader(new InputStreamReader(in, "utf-8"));
  } catch (UnsupportedEncodingException e) {
  }
  String info = null;
  try {
   info = breader.readLine();
  } catch (IOException e) {
  }
  while (info != null) {
   result += info;
   try {
    info = breader.readLine();
   } catch (IOException e) {
   }
  }
  return result;
 }

你可能感兴趣的:(职场,休闲)