首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

得到的inputstream打印中文有关问题

2012-02-06 
得到的inputstream打印中文问题Java codepublic void test() throws Throwable {String path http://10

得到的inputstream打印中文问题

Java code
    public void test() throws Throwable {        String path = "http://10.0.2.2:8080/GETDemo/MyServlet?format=name";        URL url = new URL(path);        HttpURLConnection conn = (HttpURLConnection) url.openConnection();        conn.setReadTimeout(5 * 1000);        conn.setRequestMethod("GET");        InputStream inputStream=conn.getInputStream();        int total=conn.getInputStream().available();        byte[]b=new byte[total];        inputStream.read(b);        String str=new String(b,"gbk");        System.out.println(str);    }


从服务器获得数据测试,英文可以获得,中文就打印???,我从tomcat获得的,请问问题在哪里啊???

[解决办法]
那个servlet用的是什么字符集?
或者你测试端不支持GBK字符集的也有可能
[解决办法]
穿过来的不是GBK,用GBK保存的话 就会是乱码吧

好像有方法可以得到是什么编码的

热点排行