如何解决JTextPane中序列化的中文问题? 好像有个getbyte之类的方法。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 getByte怎么用呀?那是一个完整的对象,如何转换成byte呀?我发现ObjectOutputStream和ByteArrayOutputStream都是从OutputStream扩展的,但是我无法在将ByteArrayOutputStream写入到FileInputStream。我真的很差,不要笑我。我该怎么做呀? document是一个对象,我如何把它转换为byte呢?最后我还要把它写入文件,我用FileOutputStream fstrm = new FileOutputStream(f);ByteArrayOutputStream bout = new ByteArrayOutputStream(fstrm);ObjectOutputStream ostrm = new ObjectOutputStream(bout);好像不行。那如何将ByteArrayOutputStream 写入文件呢?谢谢! 看错误的提示好象是你写如的东西不可序列化的错误难道是Document对象现在不可序列化了吗你可一这样试试ostrm.writeObject(textPane);或者你可以只写如英文,不写中文看看有没有错 只有英文的话,一点问题都没有。即使插入图片也没有问题。如果,使用JDK1.3.0就都没有问题(不需重新编译)难道是JDK把序列化重写了。那要怎么做才能真正的支持中文呢?是不是要对内容编码定义为Unicode,如何做呀!谢谢! 谢谢lianyunzxp(小刀):ostrm.writeObject(textPane);的方法没有报错。但文件读进来后,就是不正常显示。我修改后的,代码有错吗?写文件:FileOutputStream fstrm = new FileOutputStream(f);BufferedOutputStream bout = new BufferedOutputStream(fstrm);ObjectOutputStream ostrm = new ObjectOutputStream(bout);Object o = (Object)textPane;ostrm.writeObject(o);ostrm.flush();fstrm.flush();读文件:FileInputStream fin = new FileInputStream(f);BufferedInputStream bin = new BufferedInputStream(fin);ObjectInputStream istrm = new ObjectInputStream(bin);JTextPane jtp =(JTextPane) istrm.readObject();if(textPane.getDocument() != null) textPane = jtp;validate(); bug,见http://developer.java.sun.com/developer/bugParade/bugs/4513615.html,好像没有什么简单的解决方法。 jdbc无法连接数据库,相当诡异 MyEclipse下使用JDK1.7的问题 Excel 和 SQL Server数据库 jsf中 控件的 value属性和 binding属性有什么区别和联系? JAVA中空字符的疑问? Java读取数据库图片 请教如何处理浮点数toString时自动用科学计数法的问题? ResultSet 在oracle中的问题? java的applet脱离开发环境的运行问题。 数字签名请教!!分数不够可以在加!!!! 怎样读取access中的备注字段中的数据 我初学java啊~!希望多交些这方面的大虾啊~!我的qq是712779
那是一个完整的对象,如何转换成byte呀?
我发现ObjectOutputStream和ByteArrayOutputStream都是从OutputStream扩展的,但是我无法在将ByteArrayOutputStream写入到FileInputStream。
我真的很差,不要笑我。我该怎么做呀?
最后我还要把它写入文件,我用
FileOutputStream fstrm = new FileOutputStream(f);
ByteArrayOutputStream bout = new ByteArrayOutputStream(fstrm);
ObjectOutputStream ostrm = new ObjectOutputStream(bout);
好像不行。
那如何将ByteArrayOutputStream 写入文件呢?
谢谢!
难道是Document对象现在不可序列化了吗
你可一这样试试
ostrm.writeObject(textPane);
或者你可以只写如英文,不写中文看看有没有错
如果,使用JDK1.3.0就都没有问题(不需重新编译)
难道是JDK把序列化重写了。
那要怎么做才能真正的支持中文呢?
是不是要对内容编码定义为Unicode,如何做呀!
谢谢!
ostrm.writeObject(textPane);
的方法没有报错。但文件读进来后,就是不正常显示。
我修改后的,代码有错吗?
写文件:
FileOutputStream fstrm = new FileOutputStream(f);
BufferedOutputStream bout = new BufferedOutputStream(fstrm);
ObjectOutputStream ostrm = new ObjectOutputStream(bout);
Object o = (Object)textPane;
ostrm.writeObject(o);
ostrm.flush();
fstrm.flush();
读文件:
FileInputStream fin = new FileInputStream(f);
BufferedInputStream bin = new BufferedInputStream(fin);
ObjectInputStream istrm = new ObjectInputStream(bin);
JTextPane jtp =(JTextPane) istrm.readObject();
if(textPane.getDocument() != null)
textPane = jtp;
validate();