on 2005 May 26 8:15 AM
Hello,
Hello,
I have a text file which contains data in Hebrew.
I am using these lines in order to read from the file:
File inputFile = new File("C:
test.txt");
BufferedReader input = new BufferedReader (new FileReader (inputFile));
while ((line = input.readLine()) != null)
....
The problem is that when I print what I read I receive "Gibrish" letters which is impossible to read, it looks like the collection of the data doesn't keep the language. Is there any way to solve this? perhaps converting the String in some way?
Roy
Hi Roy,
this is a typical encoding issue. Here are some hints:
1. Try to read the bytes of the text instead of chars.
In other words use an InputStream instead of a Reader.
The result should be a byte array.
2. Be carefully when convert bytes to chars or String
Don't do just
String s = new String(bytes);
Do something like
String s = new String(bytes, "UTF-8");
Hope that helps a bit
Frank
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Roy,
as I stated in the other thread (the one with the URLConnection) You could use an InputStreamReader to bridge from InputStream to a Reader:
InputStream is = new FileInputStream("anyfile");
InputStreamReader isr = new InputStreamReader(is, "UTF-8");
BufferedReader br = new BufferedReader(isr);
the impotant thing is to care for the correct encoding ("UTF-8") in my example.
Best Regards
Frank
User | Count |
---|---|
77 | |
10 | |
10 | |
10 | |
10 | |
9 | |
8 | |
7 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.