android sqlite 不支持阿拉伯语
android sqlite doesn' support arabic
我的 android 应用程序上有一个 sqlite 数据库,它工作正常,但是当我尝试插入阿拉伯语时,它显示像这样的正方形 [] [] [] [] []
我使用资产文件夹中的 txt 文件将数据插入数据库,如下所示:
INSERT INTO user_table (id, name) VALUES (1,'احمد');
我尝试用 utf8 编码保存 txt 文件,但应用程序崩溃了。
我用这段代码解决了这个问题:
BufferedReader reader = new BufferedReader(new InputStreamReader(
ctx.getAssets().open("textFile.txt"), "UTF-8"));
在插入之前将您的字符串转换为 "UTF-8",如
SQLiteDatabase sq = this.getReadableDatabase();
ContentValues c = new ContentValues();
try {
String Name="نمونہ";
c.put("Name", new String(Name.getBytes(), "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
sq.insert("tableName", null, c);
我的 android 应用程序上有一个 sqlite 数据库,它工作正常,但是当我尝试插入阿拉伯语时,它显示像这样的正方形 [] [] [] [] [] 我使用资产文件夹中的 txt 文件将数据插入数据库,如下所示:
INSERT INTO user_table (id, name) VALUES (1,'احمد');
我尝试用 utf8 编码保存 txt 文件,但应用程序崩溃了。
我用这段代码解决了这个问题:
BufferedReader reader = new BufferedReader(new InputStreamReader(
ctx.getAssets().open("textFile.txt"), "UTF-8"));
在插入之前将您的字符串转换为 "UTF-8",如
SQLiteDatabase sq = this.getReadableDatabase();
ContentValues c = new ContentValues();
try {
String Name="نمونہ";
c.put("Name", new String(Name.getBytes(), "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
sq.insert("tableName", null, c);