【发布时间】:2019-07-25 10:07:26
【问题描述】:
我有一个名为条形码的 CSV 文件,我已成功将该文件导入到我的 SQLite DB 中,但问题是数据正在保存,就像我们在 CSV 文件中所拥有的一样。
我得到的数据:8.90103E+12,我想要的数据:8901030382253。
示例:
ITEM - EAN_CODE
100047253 - 8.90103E+12
100047252 - 8.90103E+12
我有两列,Ean_code 中的数据没有正确进入我的数据库。
我使用了修剪功能,但 o/p 保持不变。
我的代码:
if (exportDir.exists()) {
FileReader file = null;
try {
file = new FileReader(exportDir);
BufferedReader buffer = new BufferedReader(file);
String line = "";
int iteration = 0;
ArrayList<MasterDataModel2> arrayList_stock2 = new ArrayList<>();
while ((line = buffer.readLine()) != null) {
if (iteration == 0) {
iteration++;
continue;
}
//StringBuilder sb = new StringBuilder();
String[] str = line.split(",");
arrayList_stock2.add(new MasterDataModel2(str[0].replace("\"", ""), str[1].replace("\"", "")));
//arrayList_stock2.add(new MasterDataModel2(str[0],str[1]));
Log.d("insertTotal", "Msg:" + lastId);
}
Log.e("size",String.valueOf(arrayList_stock2.size()));
db.addAllMasterData2(arrayList_stock2);
} catch (FileNotFoundException e) {
e.printStackTrace();
//CallingImportantMethod.showToast(this, "File is not available");
} catch (IOException e) {
e.printStackTrace();
//CallingImportantMethod.showToast(this, "Something wents wrong");
}
}
【问题讨论】:
-
这个EAN_CODE在价值上有什么意义吗?因为 E+12 在科学计数法中表示等于 10^12。因此,如果确切的值很重要,那么只删除符号可能不是一个好主意,而是将其转换为正常格式然后存储。
-
没有先生 ean_code 是通用格式,例如:8.90103E+12 实际上是->8901071354103。
-
好的。所以你在 csv 中的值是逗号分隔或换行分隔的。因为我不明白你为什么用逗号分隔行。如果你能发布一个关于数据在 csv 本身中的小例子会更好。
-
先生,它不是逗号分隔的,但在记事本中打开时显示逗号分隔。
-
您能否添加 csv 的屏幕截图。如果它很大,它的一小部分会做