我有一个txt文件,其中包含UTF-8编码的单词.我把它放在“资产”文件夹中,这是我阅读它们的一种方式:
private void readWordsFromFile() {
AssetManager assetManager = context.getAssets();
try {
InputStream is = assetManager.open("words.txt");
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF8"));
String line;
while ((line = reader.readLine()) != null) {
HashMap<String, String> tempMap = new HashMap<String, String>();
tempMap.put("question", line);
line = reader.readLine();
tempMap.put("answer", line);
words.add(tempMap); // adding to an ArrayList
}
reader.close();
} catch (IOException e) {
Toast toast = Toast.makeText(context, "Error during openin learning file", Toast.LENGTH_SHORT);
toast.show();
}
}然后,我将这些单词从数组中取出来,并将它们放在TextViews中。布局xml文件指定了UFT8编码:
<?xml version="1.0" encoding="utf-8"?>但这仍然是错误的表现。我做错什么了?
发布于 2015-10-02 17:29:45
解决方案:
我必须更改txt文件编码:
资产文件夹-> my file ->右键单击->属性->将编码更改为UTF8
https://stackoverflow.com/questions/32907796
复制相似问题