日期:2014-05-17 浏览次数:20697 次
public static void main(String[] args) {
String url = "http://www.baidu.com";
String result = callUrlByGet(url,"GBK");
System.out.println(result);
}
public static String callUrlByGet(String callurl,String charset){
String result = "";
try {
URL url = new URL(callurl);
URLConnection connection = url.openConnection();
connection.connect();
BufferedReader reader = new BufferedReader(new
InputStreamReader(connection.getInputStream(),charset));
String line;
while((line = reader.readLine())!= null){
result += line;
result += "\n";
}
} catch (Exception e) {
e.printStackTrace();
return "";
}
return result;
}
try {
URL u = new URL("http://localhost:8080");
URLConnection ul = u.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(ul.getInputStream()));
String a ;
while((a = in.readLine()) !=null){
System.out.println(a);
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
public Element getTableElementListA(String url){
Source source=null;
try {
source = new Source(new URL(url));
&nb