URL Connection问题

08-08-25 mjs8781495
如此可否正常地关闭URL Connectin

 long hash = jHash.hash(("info:" + domain).getBytes());   
       
    String url = "http://"+GOOGLE_PR_DATACENTER_IPS[index-1]+"/search?client=navclient-auto&hl=en&"+   
            "ch=6"+hash+"&ie=UTF-8&oe=UTF-8&features=Rank&q=info:" + domain;   
  
    InputStream is = null;   
    URLConnection con = null;   
  
    try {   
     //proxy网络代理   
        if (proxy == null) {   
            con = new URL(url).openConnection();    
        } else {   
            con = new URL(url).openConnection(proxy);   
        }   
        con.setConnectTimeout(30000);        //设置连接超时时间   
           
        is = con.getInputStream();          //获取数据流   
            
        byte [] buff = new byte[1024];   
        int read = is.read(buff);   
          
        while (read > 0) {   
            googlePrResult = new String(buff, 0, read);      
            read = is.read(buff);   
        }   
           
        googlePrResult = googlePrResult.split(":")[2].trim();   
        result = new Long(googlePrResult).intValue();   
    } catch (Exception e) {   
        result = -1;   
    } finally {   
        if (is != null) {   
            try {   
    is.close();   
} catch (IOException e) {   
    e.printStackTrace();   
}   
        }   
    }  

<p>

banq
2008-08-27 16:35
应该可以,或者自己动手测试一下这个代码

猜你喜欢