URL url = new URL(path);//path为url路径 HttpURLConnection conn = (HttpURLConnection) url.openConnection();// 利用HttpURLConnection对象,我们可以从网络中获取网页数据. conn.setDoInput(true); conn.connect(); InputStream is = conn.getInputStream(); // 得到网络返回的输入流
InputStreamReader isr = new InputStreamReader(is, "utf-8");
BufferedReader br = new BufferedReader(isr);
String s = null;
while ((s = br.readLine()) != null) {// 使用readLine方法,一次读一行
}
br.close();
时间: 2024-10-29 04:00:25