[英]How can I read a text file in android with Turkish characters?
I want to read a text file and I can read with below written code. 我想阅读一个文本文件,并且可以阅读下面的代码。 But my text file include Turkish characters like "ü", "ç", "ğ", "ö"... When I read that text file, I can see these characters.
但是我的文本文件包含土耳其字符,例如“ü”,“ç”,“ğ”,“ö” ...当我阅读该文本文件时,可以看到这些字符。 For example, my word which written in text file is "okçu" but I see on my phone like "ok?u".
例如,我在文本文件中写的单词是“okçu”,但在手机上却看到“ ok?u”。 How can fix it?
如何解决?
public static String readTextFile(Context ctx, int resId) {
InputStream inputStream = ctx.getResources().openRawResource(resId);
InputStreamReader inputreader = new InputStreamReader(inputStream);
BufferedReader bufferedreader = new BufferedReader(inputreader);
String line;
StringBuilder stringBuilder = new StringBuilder();
try {
while ((line = bufferedreader.readLine()) != null) {
stringBuilder.append(line);
stringBuilder.append('\n');
}
} catch (IOException e) {
return null;
}
return stringBuilder.toString();
}
I faced this problem when I received the response from my HttpClient
for the first time. 第一次收到
HttpClient
的响应时,我遇到了这个问题。 I managed to solve it by specifying the encoding within the InputStreamReader
object's instantiation. 我设法通过在
InputStreamReader
对象的实例化中指定编码来解决此问题。 I hope it might help you as well. 希望对您也有帮助。
InputStream inputStream = ctx.getResources().openRawResource(resId);
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream,"UTF8"),8);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.