java - xstream handles non-english character -


I have the following code:

  / * * To change this template, Choose the device. Templates * and open the template in the editor. * Package / helloworld; Import com.thoughtworks.xstream.xstream; Import java.io.file; Import java.io.FileOutputStream; Import java.io.InputStream; Import java.io.OutputStream; Import javax.swing.JOptionPane; / ** * * Author @ yachohock * / public class test {@SuppressWarnings ("uncheck") public static & lt; A & gt; A to XML (class C, file file) {Xstream Xstream = new Xstream (); InputStream inputstream = faucet; Try {InputStream = new java.io.FileInputStream (file); Commodity object = xStream.fromXML (inputstream); If (C. Instance (object)) returns (A) object; }} Hold (exception exp) {exp.printStackTrace (); } Finally {if (inputstream! = Zero} {try {inputstream.close (); Inputstream = faucet; } Hold (java.io.IOException exp) {exp.printStackTrace (); Return tap; }}} Return tap; } @SuppressWarnings ("uncheck") public static & lt; A & gt; A to XML (class C, string filespath) {return (a) to XML (c, new file (filepath)); } Public stable boolean toxml (object object, file file) {XStream xStream = New XStream (); OutputStream Output Stream = Null; {Outputstream = Try New FileOutputStream (File); XStream.toXML (object, outputstream); } Hold (exception exp) {exp.printStackTrace (); return false; } Finally {if (outputstream! = Null} {try {outputstream.close ()); Output stream = null; } Hold (java.io.IOException exp) {exp.printStackTrace (); return false; }}} Be true; } Public stable boolean toxml (object object, string filepath) {back to xml (object, new file (filepath)); } Public static zero main (string array []) {string s = "\ u6210 \ u4EA4 \ u91CF"; // print ??? Println (s); // Fine! Show 成交量 Publish Job. Show message dialects (empty, s); ToXML (S, "C: \ .xml"); String o = xml (string class, "c: \ .xml"); // show ??? Employmentpan Shomos Dialliag (vacant, o); }}  

I run the following code in Windows Vista with a command prompt.

1) I know why the console unable to print Chinese characters in System.out.println?

2) I open the xstream file, the saved value is

   

How can I save Xstream Chinese characters correctly?

Thank you. According to itempop = "text">

, it generates output (1) with your platform default encoding, and (2 ) Which is really a bad combination without an XML introduction.

Re-evaluate using the frequently asked question toxml (author) . If you use OutputStreamWriter , you can specify the encoding during the creation. Since Xstream does not emit a preamble, therefore, I recommend using "UTF-8", as is the need for XML imagery.

Alternatively, I think that you can follow any of the other recommendations in the FAQ, and manually write an XML introduction into the stream with your default encoding; I do not recommend it I am


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -