Asked 10 years, 4 months ago. Active 10 years, 4 months ago. Viewed 6k times. Currently I am reading. But unicode characters do not appear as they should. Any ideas how to change the above code, for unicode to work?
Roger Roger 6, 20 20 gold badges 56 56 silver badges 86 86 bronze badges. Add a comment. Active Oldest Votes. If you don't know what encoding your file uses, we don't either. This is a prerequisite to read the file correctly. Another possibility is that the font you're using to display the read text doesn't contain the glyphs for all the characters of your text.
Roger, you'll need to ascertain the encoding to use by checking with the code that wrote the file, or looking at the bytes in the file in a hexdump. Just trying different ones and hoping to chance upon one that happens to work on your test data is not a robust development strategy. Then the encoding is probably Windows en. If your JVM doesn't support this encoding, using ISO as encding name might work depending on what characters are in the text.
Active Oldest Votes. Well, there are three potential sources of problems I can see: The regular expression may be incorrect. Do you really need to use a regular expression? Are you trying to match a pattern, or just a simple string? You should dump out the input string in terms of its Unicode characters see code later. You may well be reading the file in the wrong encoding. Currently you're using FileReader which always uses the platform default encoding. What's the encoding of the file you're trying to read?
UTF-8 which matches the file. Jon Skeet Jon Skeet 1. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available.
The java. With the InputStreamReader class, you can convert byte streams to character streams. You use the OutputStreamWriter class to translate character streams into byte streams. The following figure illustrates the conversion process:. When you create InputStreamReader and OutputStreamWriter objects, you specify the byte encoding that you want to convert. The example that follows shows you how to perform character-set conversions with the InputStreamReader and OutputStreamWriter classes.
The full source code for this example is in StreamConverter. This program displays Japanese characters.
0コメント