- EncodingUtils.getString(data.getBytes("GB2312"), "UTF-8");
如果直接getBytes()的话是以iso88590-1编码获取字节。
- URL myFileUrl = null;
- myFileUrl = new URL(url);
- HttpURLConnection conn;
- conn = (HttpURLConnection) myFileUrl.openConnection();
- conn.setDoInput(true);
- conn.connect();
- InputStream is = conn.getInputStream();
- BufferedReader br = new BufferedReader(new InputStreamReader(is,
- "GB2312"));
- sb = new StringBuffer();
- String data = "";
- while ((data = br.readLine()) != null) {
- sb.append(data+"\n");
- }
- String result = sb.toString();
- sb = new StringBuffer();
- HttpEntity entity = response.getEntity();
- InputStream is = entity.getContent();
- BufferedReader br = new BufferedReader(
- new InputStreamReader(is,"GB2312"));
- String data = "";
- while ((data = br.readLine()) != null) {
- sb.append(data);
- }
- String result = sb.toString();
- public void readTxt(){
- ByteArrayBuffer sb = new ByteArrayBuffer(5000);
- try {
- InputStream ip = asset.open("aa.txt");
- BufferedReader br = new BufferedReader(new InputStreamReader(ip,"GB2312"));
- String temp = null;
- int cur =0;
- // while((temp = br.readLine())!=null){
- // sb.append(temp);
- // }
- while((cur = br.read())!=-1){
- sb.append(cur);
- }
- textView.setText( EncodingUtils.getString(sb.toByteArray(),"GB2312"));
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }