我正在尝试创建外部字典,但是当我尝试从txt文件加载字典数据时。它代表这样 。这是我用来读取该文件的方法:
private WordList(Context context) throws IOException {
mWordList = new ArrayList<>();
AssetManager am = context.getAssets();
InputStream is;
StringBuilder stringBuilder=new StringBuilder("");
is = am.open("dat.txt");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is));
while (bufferedReader.readLine()!=null){
stringBuilder.append(bufferedReader.readLine());
Log.d("String",stringBuilder.toString());
StringTokenizer stringTokenizer = new StringTokenizer(stringBuilder.toString(),",;'");
Word word = new Word();
StringBuilder def = new StringBuilder();
/* for (int i=0; i<stringTokenizer.countTokens();i++){
if(i==0){
word.setWrodName(stringTokenizer.nextToken());
if (i==1){
def.append(stringTokenizer.nextToken());
}
if (i==2){
def.append(", ");
def.append(stringTokenizer.nextToken());
}
if (i==3){
def.append(", ");
def.append(stringTokenizer.nextToken());
}
word.setWordDefinition(def.toString());
}
def.delete(0,def.length());
}*/
stringBuilder.delete(0,def.length());
mWordList.add(word);
}
is.close();
Log.d("String",stringBuilder.toString());
}
在行回收视图中,它显示带符号和数字的笔划。
答案 0 :(得分:3)
您可以尝试传递编码吗?
// Change encoding to "UTF-8" or whatever you want.
BufferedReader in = new BufferedReader(new InputStreamReader(stream, encoding));
或尝试这种方式
Reader in = new InputStreamReader(new FileInputStream("file"), "UTF-8"));
答案 1 :(得分:0)