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

    }

  

你可能感兴趣的:(android)