Android学习笔记之读取文件内容乱码问题

public String download(String Url) throws IOException{
		
		StringBuffer stringbuffer = new StringBuffer();
		String line = null;
		BufferedReader br = null;
		// 创建一个URL对象
	    url = new URL(Url);
	    // 创建一个Http连接
	    HttpURLConnection httpurlconnection =(HttpURLConnection)url.openConnection();
	    // 使用IO流读取数据
	    br = new BufferedReader(new InputStreamReader(httpurlconnection.getInputStream(),"GB2312"));
	    while((line = br.readLine())!= null){
	    	stringbuffer.append(line);
	    }
	    br.close();
	    return stringbuffer.toString();
	}


最重要的是这句:br = new BufferedReader(new InputStreamReader(httpurlconnection.getInputStream(),"GB2312"));

后面加了一个参数:"GB2312"

你可能感兴趣的:(android,String,IO,null,url,download)