Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem writing Emdash to txt file on Solaris OS 5.9  RSS feed

 
Amrit Tiwana
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I m writing a simple program as below to write EMdash(\u2014) to a file.

FileOutputStream fout =null;
try {
fout = new FileOutputStream("c:\\try.txt");
fout.write("\u2014 Em dash".getBytes());
}
catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
fout.close();
}
catch (IOException ex) {
}
}

On windows it is working fine giving proper output file(� Em dash). But on Solaris OS 5.9, It is giving (? Em dash). It is working fine for characters upto the range \u255.

Please let me know where I'm wrong.

Thanks
 
Harald Kirsch
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This looks like on the Solaris you mention the default character encoding, as is used by String.getBytes(), can not encode the emdash. Consequently the character ends up as a question mark.

Try String.getBytes(String charsetName) and use "UTF-8" encoding.

Harald.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!