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();

解决方案 »

  1.   


        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();
      

  2.   

    感谢楼上两位的回复。我要实现的是客户端每个用户都可以通过页面上载本地html文件,而对于我服务器来说我需要把客户端上载的html文件的源代码读出来放到一个String中然后进行处理,这该怎么办?