自做了一个android小程序,用于访问本地的一个web项目下的一个网页。
用浏览器去访问该该网页能够正常显示中文,而用android程序通过流去读取该网页,
中文会被 "南少林" 之类的代码替代。
 <%@ page language="java" import="java.util.*" contentType="text/html; charset=GBK" pageEncoding="GBK"%>
<%@ taglib uri="/struts-tags" prefix="s" %><s:property value="str"/>web网页如上:  <s:property value="str"/>  通过浏览器访问会显示如下语句
[{id:110,name:"太极宗师",time:28},{id:111,name:"南少林",time:38},{id:112,name:"楚留香",time:30}] 通过 android 程序读取网页信息代码如下: public static String getHtml(String textsrc) throws Exception {

 URL url=new URL(textsrc);
 HttpURLConnection URLConnection=(HttpURLConnection) url.openConnection();
 URLConnection.setConnectTimeout(5000);
 URLConnection.setRequestMethod("GET");
 
 byte by[];
 if(URLConnection.getResponseCode()==200)
 {
 InputStream  inputStream=URLConnection.getInputStream();
 by=Inpututil.getinput(inputStream);
 inputStream.close();
 return new String(by);
 }
 

return null;
}
public class Inpututil { public static byte[] getinput(InputStream input) throws Exception {
ByteArrayOutputStream outputStream=new ByteArrayOutputStream();
byte by[]=new byte[1024];
int len=0;
while((len=input.read())!=-1)
{
input.read(by);
outputStream.write(by);
}

input.close();
byte bt[]=outputStream.toByteArray();
System.out.println(new String(bt,"GBK"));//想在这里输出与浏览器中一样的内容,可输出乱码,求解
return bt;
}}