以下是一个通过
url 进行请求数据,通过该url地址进行读取,读取格式为字符串形式!直接运行该main 方法就可以得到结果形式!
package com.wm;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
/**
* 通过 url 读取数据 测试类
* @author wangmeng
*
*/
public class TestUrl {
public static void main(String[] args) {
try {
URL url = new URL("http://wangmengbk.javaeye.com/blog/378121");
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String str="";
StringBuffer sb= new StringBuffer();
while ((str= in.readLine()) != null)
{
sb.append(str);
}
System.out.println(sb.toString());
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}