Forum Stats

  • 3,852,403 Users
  • 2,264,102 Discussions


how to handle multibyte characters in my java program

807580 Member Posts: 33,048 Green Ribbon
edited Dec 17, 2009 12:39PM 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?


  • 807580
    807580 Member Posts: 33,048 Green Ribbon
    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.