从文本文件中读取外来单词时不显示Unicode

时间:2016-09-06 09:00:54

标签: java android unicode

我正在尝试创建外部字典,但是当我尝试从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());

}

在行回收视图中,它显示带符号和数字的笔划。

2 个答案:

答案 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)

  1. 检查数据库编码类型utf8,utf16,latin .............
  2. 相应地对UI进行了更改。喜欢&lt;%@ page contentType =“text / html; charset = UTF-8”%&gt;在html或jsp中
  3. 检查dat.txt的字符编码。