Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 865069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:34:57+00:00 2026-05-15T09:34:57+00:00

I have the following code : /* * To change this template, choose Tools

  • 0

I have the following code :

/*
 * To change this template, choose Tools | 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 yccheok
 */
public class Test {
    @SuppressWarnings("unchecked")
    public static <A> A fromXML(Class c, File file) {
        XStream xStream = new XStream();
        InputStream inputStream = null;

        try {
            inputStream = new java.io.FileInputStream(file);
            Object object = xStream.fromXML(inputStream);
            if (c.isInstance(object)) {
                return (A)object;
            }
        }
        catch (Exception exp) {
            exp.printStackTrace();
        }
        finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                    inputStream = null;
                }
                catch (java.io.IOException exp) {
                    exp.printStackTrace();
                    return null;
                }
            }
        }

        return null;
    }

    @SuppressWarnings("unchecked")
    public static <A> A fromXML(Class c, String filePath) {
        return (A)fromXML(c, new File(filePath));
    }

    public static boolean toXML(Object object, File file) {
        XStream xStream = new XStream();
        OutputStream outputStream = null;

        try {
            outputStream = new FileOutputStream(file);
            xStream.toXML(object, outputStream);
        }
        catch (Exception exp) {
            exp.printStackTrace();
            return false;
        }
        finally {
            if (outputStream != null) {
                try {
                    outputStream.close();
                    outputStream = null;
                }
                catch (java.io.IOException exp) {
                    exp.printStackTrace();
                    return false;
                }
            }
        }

        return true;
    }

    public static boolean toXML(Object object, String filePath) {
        return toXML(object, new File(filePath));
    }

    public static void main(String args[]) {
        String s = "\u6210\u4EA4\u91CF";
        // print ???
        System.out.println(s);
        // fine! show 成交量
        JOptionPane.showMessageDialog(null, s);
        toXML(s, "C:\\A.XML");
        String o = fromXML(String.class, "C:\\A.XML");
        // show ???
        JOptionPane.showMessageDialog(null, o);
    }
}

I run the following code through command prompt in Windows Vista.

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

2) I open up the xstream file. The saved value is

<string>???</string>

How can I make xstream save Chinese Character correctly?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T09:34:57+00:00Added an answer on May 15, 2026 at 9:34 am
    XStream xStream = new XStream(new DomDriver("UTF-8")); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following jquery code: jQuery(function(){ jQuery(select#rooms).change(function(){ var options = ''; jQuery.getJSON(/admin/selection.php,{id: jQuery(this).val(),
I have the following code based on this great template for making custom WordPress
I have the following code in a controller: $this->viewdata->scripts = array( 'http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js', 'jstree/jquery.jstree-1.0-rc2.js', 'jquery.hotkeys-0.8.js',
Anything I have tried didn't work. Currenly I have following code to change asp.net
I have the following code that when i change the drop down it doesnt
I have the following code that i am trying to change from a regular
I have the following code: // After 8 seconds change the slide... var timeout
I have the following code setup: http://jsfiddle.net/bABHU/2/ Had to change it a little bit
How to change the width/height if I have the following code and using php:
I have the following SQL code that runs against a Change Request database. Each

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.