Why am i getting ?? when i try to read ä character from a text file in java?

后端 未结 2 1508
南旧
南旧 2021-01-29 05:51

I am trying to read text from a text file. There are some special characters like å,ä and ö. When i make a string and print out that string then i get ?? from these special char

相关标签:
2条回答
  • 2021-01-29 06:17

    Check here for the lists of Java supported encodings

    Most common single-byte encoding that includes non-ascii characters is ISO8859_1; maybe your file is that, and you should specifiy that encoding for your FileInputStream

    0 讨论(0)
  • 2021-01-29 06:25

    The problem might not be with the file but with the console where you are trying to print. I suggest you follow the following steps

    1. Make sure the file you are reading is encoded in UTF-8.
    2. Make sure the console you are printing to has the proper encoding/charset to display these characters

    Finally, this article Unicode - How to get characters right? is a must read.

    0 讨论(0)
提交回复
热议问题