I am trying to read a UTF-8 encoded txt file, which has some turkish characters. Basically I am have written an axis based web service, which reads this file and send the output back as a string. Somehow I am not able to read the characters properly. The code is very simple as mentioned here:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CodingErrorAction;
public class TurkishWebService {
public String generateTurkishString() throws IOException {
InputStream isr = this.getClass().getResourceAsStream(
"/" + "turkish.txt");
BufferedReader in = new BufferedReader(new InputStreamReader(isr,
"UTF8"));
String str;
while ((str = in.readLine()) != null) {
System.out.println(str);
}
in.close();
return str;
}
public String normalString() {
System.out.println("webService normal text");
return "webService normal text";
}
public static void main(String args[]) throws IOException {
new TurkishWebService().generateTurkishString();
}
}
Here are the contents of turkish.txt, just one line
Assalğçğıİİööşş
I am getting the stdout as
Assal?τ????÷÷??
Please suggest what am I doing wrong here.