File source = new File("C:\\temp\\aaa.html");
BufferedReader reader = new BufferedReader(new FileReader(source));
StringBuffer result = new StringBuffer();
String tempLine = null;
while ((tempLine = reader.readLine()) != null) {
result.appand(tempLine);
}
reader.colse();
BufferedReader reader = new BufferedReader(new FileReader(source));
StringBuffer result = new StringBuffer();
String tempLine = null;
while ((tempLine = reader.readLine()) != null) {
result.appand(tempLine);
}
reader.colse();
String result;
String url="http://www.csdn.net";
HttpClient client=new HttpClient();
HttpMethod method=new GetMethod(url);
int statusCode = -1;
for (int attempt = 0;statusCode == -1 && attempt < 3; attempt++) {
try{
statusCode = client.executeMethod(method);
}catch(Exception ex){
System.err.println("无法连接");
}
}
if (statusCode == -1) {
method.releaseConnection();
System.err.println("无法连接");
return;
}
result = new String(method.getResponseBody());
method.releaseConnection();