java抓取网页的内容

public static String getHtmlReadLine(String httpurl){
     String CurrentLine="";
         String TotalString="";
         InputStream urlStream;
         String content="";
         try {
            URL url = new URL(httpurl);
           //  URL url = new URL("http://www.sugarinfo.net/dissertation/gctinfo/");
             HttpURLConnection connection = (HttpURLConnection)url.openConnection();
             connection.connect();
             urlStream = connection.getInputStream();
             BufferedReader reader = new BufferedReader(
             new InputStreamReader(urlStream,"utf-8"));
             while ((CurrentLine = reader.readLine()) != null) {
             TotalString += CurrentLine+"\n";
             /**换行的地方主要是在这里**/
                  }
               content =  TotalString;
           //  System.out.println(content);
         } catch (Exception e) {
      
             e.printStackTrace();
         }
  return content;
  
 }

你可能感兴趣的:(java,.net)