编码转换
String str;//gb2312编码字符串
String strGB = new String(str.getBytes(),"GB2312");
String strUTF = new String(strGB.getBytes(),"UTF-8");试试吧!
String str;//gb2312编码字符串
String strGB = new String(str.getBytes(),"GB2312");
String strUTF = new String(strGB.getBytes(),"UTF-8");试试吧!
URL url=new URL(xmlPath);
in = url.openStream();
InputSource source=new InputSource(new InputStreamReader(inputStream,"utf-8"));
parser.parse(source, handler);其中inputStream就是获取通过xml获取到的输入流,parser就是SAXParser对象,
这个的话,我想了一下,要转的话,也只能在解析xml文件每个标签内的内容的时候转,就是
在characters方法中,对获取到的标签内容,进行转码,但是这样也是不行的,晕了,不知道
改在那个位置进行转码了。。
InputStream in = null;
URL url=new URL(xmlPath);
in = url.openStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int len = 0;
byte[] datas = new byte[1024];
while((len = in.read(datas,0,1024)) != -1)
baos.write(datas, 0, len);
String strGB = new String(baos.toByteArray(),"GB2312");
String strUTF = new String(strGB.getBytes(),"UTF-8");
InputSource source = new InputSource(strUTF);
parser.parse(source, handler);试试吧
然后用获取到的这个格式去解析整个xml文件