dcsimg
why I get different result in different platform ?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   lai_ameng
Posted On:   Monday, April 29, 2002 02:58 AM

I execute following procedure in win2000 and Solaris platform respectively. I get corrent result file in win2000,but in Solaris,every chinese character is displayed as question mark.why? how can I do? import java.io.*; import java.util.Vector; public class Testor { PrintWriter os = null; public Testor(OutputStream outStream) { os = new PrintWriter(outStream); } public void outContentBody() { os.println("in os ÐÍÊä³öÁ÷"); //output chinese character os.flush(); } public static void main(String[] args) { try { FileOutputStream f =    More>>

I execute following procedure in win2000 and Solaris platform respectively.
I get corrent result file in win2000,but in Solaris,every chinese
character is displayed as question mark.why? how can I do?


import java.io.*;

import java.util.Vector;

public class Testor {

PrintWriter os = null;



public Testor(OutputStream outStream) {

os = new PrintWriter(outStream);

}



public void outContentBody() {

os.println("in os ÐÍÊä³öÁ÷"); //output chinese character

os.flush();

}


public static void main(String[] args) {

try {

FileOutputStream f = new FileOutputStream("testor.txt");

Testor testor = new Testor(f);

testor.outContentBody();

f.close();

} catch(Exception ex) {

System.out.println(ex.toString());

}

}


}

   <<Less

Re: why I get different result in different platform ?

Posted By:   Stephen_Ostermiller  
Posted On:   Monday, April 29, 2002 04:28 AM

You are using classes that have no methods for specifing the character encoding to use. They use the system default character encoding which is different on different systems.


You should construct your printwriter so that it writes bytes in the character encoding of your choice. If you want chinese characters, you might want to use Chinese Simplified (GB2312).


os = new PrintWriter(new OutputStreamWriter(outStream, "GB2312"));
About | Sitemap | Contact