80,351
社区成员
发帖
与我相关
我的任务
分享
// 通过url获取数据
public static String Getpath(String path) {
StringBuffer buffer = new StringBuffer();
URL url;
try {
url = new URL(path);
HttpURLConnection connection = (HttpURLConnection) url
.openConnection();
InputStream stream = connection.getInputStream();
byte[] by = new byte[1024];
int len = 0;
while ((len = stream.read(by)) != -1) {
buffer.append(new String(by, 0, len, "UTF-8"));
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Log.e("TAG", buffer.toString());
return buffer.toString();
}