2

from past 5 hours i have been working on an issue related to french characters.

The actual problem is like, some french characters are stored in database(oracle), and m trying to read them and output to a word file.

to surprise, all the french assented characters are displayed as '?'. initially i thought it would be the problem with encoding format and tried to work on it. but, i could not figure it out.

The java version which i am running my app is an 1.4, with tomcat 5. I narrowed my issue and thought of printing normal french characters on console, to my surprise they are printed as ??. then after surfing for about 2 hours, i understood a little on encoding and default charset which java uses. Interestingly i found 2 methods on google that could fit to my soultion. but as i tried them, they were of no use, they are still printing ?? on console. Could you please clarify me or provide me the solution, or where m going wrong.

Here are code snippets which i have tried.

public static void test() {
    System.out.println("in test");
 PrintStream ps = null;
 String javaString = 
  "caractères français :  à é \u00e9";  // Unicode for "é"

 try {
   ps = new PrintStream(System.out, true, "Cp850");
 } catch (UnsupportedEncodingException error) {
   System.err.println(error);
   System.exit(0);
 }

 ps.println(javaString);
}

The second one is:

public static void main(String args[]){
String javaString = 
  "caractères français :  à é \u00e9";  // Unicode for "é"
try {
  // output to the console
  Writer w = 
    new BufferedWriter
       (new OutputStreamWriter(System.out, "Cp850"));
  w.write(javaString);
  w.flush();
   test();
  w.close();  
  test();
  }
catch (Exception e) {
  e.printStackTrace();
  }
}
4

0 回答 0