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) {
}
}
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;
}
}
转载于:https://blog.51cto.com/websky/273294