java读取URL 
返回1M 的 XML文件
浏览器直接打开5秒钟 
使用代码 却要50多秒 求大神指导

解决方案 »

  1.   

    看看是不是HttpClientSSL.getContent1这个方法里有太慢的写法。
      

  2.   

    deubg 看在什么地方卡了。 就知道那步问题了
      

  3.   

     
    String url="####################";
    URLConnection uc=null;
        InputStream in=null;
        InputStreamReader rd=null;
        List<MatchInfo> mList1 = new ArrayList<MatchInfo>();
    try {
    Date stratDate = new Date();
    uc = new URL(url).openConnection();
    uc.setConnectTimeout(10000);
    uc.setDoOutput(true);
    in  = new BufferedInputStream(uc.getInputStream());
    rd = new InputStreamReader(in, "UTF-8");
    java.io.BufferedReader br = new java.io.BufferedReader(rd);
    String tempbf;
    StringBuffer temp=new StringBuffer();
    while ((tempbf = br.readLine()) != null) {
    temp.append(tempbf);
    temp.append("\r\n");
    }
    //String content  = HttpClientSSL.getContent1(url);
    System.out.println("抓取 结束" + " 耗时----"
    + (stratDate.getTime() - new Date().getTime()) / 1000.0);这段被注释掉//String content  = HttpClientSSL.getContent1(url);
      

  4.   

    String content  = HttpClientSSL.getContent1(url);
    这前后加个时间看看执行了多长时间。这之前的代码应该很快
      

  5.   

    uc = new URL(url).openConnection();
    应该是这里,因为网络的原因。
      

  6.   

    另外 初始化 StringBuffer/StringBuilder时传入一个足够的初始长度。