Forum Stats

  • 3,728,472 Users
  • 2,245,631 Discussions
  • 7,853,549 Comments

Discussions

how to handle multibyte characters in my java program

807580
807580 Member Posts: 33,048
edited December 2009 in Java Programming
My java program residing on a unix server reads from various files that have Finnish characters and writes the data into one single file. While doing this, it replaces them with ???.

Where can I specify encoding so that it handles these special characters?

Comments

  • 807580
    807580 Member Posts: 33,048
    Don't rely upon the default encoding but use the appropriate one.

    For example instead of this:
    public InputStreamReader(InputStream in)
    //Create an InputStreamReader that uses the default charset. 
    use one of these:
    public InputStreamReader(InputStream in, String charsetName) 
    public InputStreamReader(InputStream in, Charset cs)
    public InputStreamReader(InputStream in, CharsetDecoder dec)
  • DrClap
    DrClap Member Posts: 25,479
    Alternatively, if you aren't doing anything with the text in those files but you're only copying it from one place to another, then don't even use Readers and Writers. Just use InputStreams and OutputStreams to copy the bytes in the files without changing them.
This discussion has been closed.