Java: Readers and Encodings

后端 未结 5 451
臣服心动
臣服心动 2020-12-05 06:04

Java\'s default encoding is ASCII. Yes? (See my edit below)

When a textfile is encoded in UTF-8? How does a Reader know that he has to use

5条回答
  •  独厮守ぢ
    2020-12-05 06:35

    Java's default encoding depends on your OS. For Windows, it's normally "windows-1252", for Unix it's typically "ISO-8859-1" or "UTF-8".

    A reader knows the correct encoding because you tell it the correct encoding. Unfortunately, not all readers let you do this (for example, FileReader doesn't), so often you have to use an InputStreamReader.

提交回复
热议问题