jibx中文乱码

lwei_998 2010-02-26 02:46:45
JiBX只支持Java标准的字符集,也就是说我们常用的GB2312和GBK不在支持行列之内。谈谈大家有什么好的解决方法。
...全文
121 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
lee986617310968 2011-02-19
  • 打赏
  • 举报
回复
到myeclipse里面设置代码就行了
mklj555 2011-01-22
  • 打赏
  • 举报
回复
扑捉异常应该可以了吧!
在不然就是转型咯
zhangdong198677 2011-01-20
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 lwei_998 的回复:]
问题想复杂了,简单的转码就搞定了



Java code

package com.hch.testjibx;

import java.io.*;

import org.jibx.runtime.BindingDirectory;
import org.jibx.runtime.IBindingFactory;
import org.jibx.runtime.IMar……
[/Quote]

你这个方法不行啊,试了不好用。
lwei_998 2010-02-26
  • 打赏
  • 举报
回复
问题想复杂了,简单的转码就搞定了



package com.hch.testjibx;

import java.io.*;

import org.jibx.runtime.BindingDirectory;
import org.jibx.runtime.IBindingFactory;
import org.jibx.runtime.IMarshallingContext;
import org.jibx.runtime.IUnmarshallingContext;

public class Test {

/**
* @param args
*/


public static void main(String[] args) {
// TODO Auto-generated method stub
try{
IBindingFactory bfact = BindingDirectory.getFactory(TeleCustomer.class);
// unmarshal customer information from file
IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
File dataFile = new File("E:\\jbossvss\\testjibx\\classes\\data.xml");
System.out.println("filepath:"+dataFile.getAbsolutePath());
InputStream in = new FileInputStream(dataFile);
FileInputStream testfile=new FileInputStream("E:\\jbossvss\\testjibx\\classes\\data.xml");
InputStreamReader i=new InputStreamReader(testfile,"GBK");


TeleCustomer customer = (TeleCustomer)uctx.unmarshalDocument(in, null);
TeleCustomer customer1 = (TeleCustomer)uctx.unmarshalDocument(i, null);
IMarshallingContext ctx = bfact.createMarshallingContext();
ByteArrayOutputStream os = new ByteArrayOutputStream();
ctx.marshalDocument(customer1, "UTF-8", null,os);
//xstr = new String(os.toString().getBytes("GBK"),"GBK");


System.out.println(new String(os.toString().getBytes("GBK"),"UTF-8"));

System.out.println("customer.phone:"+customer.getPhone());
System.out.println("customer1.phone:"+customer1.getPhone());
System.out.println("customer.addressName:"+customer.getAddress().getAddressName());
System.out.println("customer1.addressName:"+customer1.getAddress().getAddressName());


}catch(Exception e){
e.printStackTrace();
}
}


}

51,397

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧