Android通过http与servlet通讯引起的乱码问题? http://developer.android.com/reference/java/net/URLEncoder.html 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 上下你的流相关的读取代码,加入下charset统一下就行了,utf-8比较通用,但是缺点就是太费资源了,要占3个字节,哈哈 url = new URL(urlstr); //得到HTTPURL资源 HttpURLConnection hc = (HttpURLConnection)url.openConnection(); //得到输入流 in= hc.getInputStream(); //使用InputStream的anailalble方法得到输入流的字节数 int n=in.available(); //声明一个字节数组 byte[] buf=new byte[n]; while(in.read(buf)!=-1){ //转换字符编码 String str=new String(buf,"GB2312"); // String str=new String(buf); sb.append(str); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } finally{ try{ in.close(); } catch(Exception e){ e.printStackTrace(); } } //返回字符串并过滤'\r' return sb.toString().replace("\r\n", "\n"); 安置wooboo时 出现问题 android添加希伯来语 ,荷兰语 Android出现Waiting for sdk to finish loading 屏幕关闭时的Notification问题 ListView中的EditText问题 求助,CursorFactory()的实现 如何显示多个应用程序 Android简单的OTG功能 请教大神,LayoutInflater和View.linflate出来的Layout不能操作 怎样给Fragment中的按钮添加点击事件? 如何根据设备屏幕的大小自动调整界面的大小 listView显示来自网络的图片是如何实现?
//得到HTTPURL资源
HttpURLConnection hc = (HttpURLConnection)url.openConnection();
//得到输入流
in= hc.getInputStream();
//使用InputStream的anailalble方法得到输入流的字节数
int n=in.available();
//声明一个字节数组
byte[] buf=new byte[n];
while(in.read(buf)!=-1){
//转换字符编码
String str=new String(buf,"GB2312");
// String str=new String(buf);
sb.append(str);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
try{
in.close();
}
catch(Exception e){
e.printStackTrace();
}
}
//返回字符串并过滤'\r'
return sb.toString().replace("\r\n", "\n");