Android从网络下载XML输出流或者字符串(知识积累)

public String downloadXML(final String urlStr) 
    {
    	StringBuffer sb=new StringBuffer();
    	String line=null;
    	BufferedReader buffer=null;
    	
    	try {
    		URL url=new URL(urlStr);
    		
    		HttpURLConnection urlConn=(HttpURLConnection)url.openConnection();
    		
    		InputStream inputStream = urlConn.getInputStream();
    		
    		buffer=new BufferedReader(new InputStreamReader(inputStream));
    		
    		while ((line= buffer.readLine()) != null) {
				sb.append(line);
				
			}

		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			try {
				buffer.close();
			} catch (Exception e2) {
				e2.printStackTrace();
			}
		}
    	
    	
    	return sb.toString();
    }

  

posted @ 2011-10-20 22:21 Sir。 阅读(...) 评论(...) 编辑 收藏