将数据从文件复制到sqlite

时间:2014-09-23 14:45:46

标签: android sqlite bufferedreader

我正在尝试将某些.csv文件中的内容复制到数据库中。因为我在该文件中有法语文本。我无法将确切的内容复制到数据库中。当我调试它时,我发现它是bufferedreader的问题。我用Google搜索解决方案,但无法解决问题。我要复制的代码是这样的。像“crÃa”这​​样的单词会读作“crEa”。请帮帮我。

reader = new BufferedReader(
                new InputStreamReader(mContext.getAssets().open("some.csv"),"UTF-8"));

            String mLine = null;
            mLine = reader.readLine();
            db.beginTransaction();
            do {
                if(mLine == null){
                    return;
                }
                String[] splitLine = SplitLine(mLine);
                Log.i("Database", "Splitted text is "+ splitLine);
                Log.i("Database", "read line is "+mLine);
                ContentValues cv = new ContentValues();


                long i = db.insert(table, null, cv);
                if(i == -1){
                    Log.w("Database", "Failed to insert into database");
                }
            }while ((mLine = reader.readLine())!= null);
            db.setTransactionSuccessful();
            db.endTransaction();

0 个答案:

没有答案