【发布时间】:2016-08-08 20:27:33
【问题描述】:
我有一个应用程序允许用户在平板电脑上签名并生成图像。这部分我正在确认,因为我可以在创建和保存图像后查看它们。
我正在使用以下代码将它们写入 .csv 文件。
//region - Create CSV file
writer = new CSVWriter(new FileWriter(sdCardPath + "Orders_Summary_Report.csv"), ',', CSVWriter.NO_QUOTE_CHARACTER, CSVWriter.DEFAULT_ESCAPE_CHARACTER, "\r\n");
//writer.writeNext(CSVcursor.getColumnNames()); //Write the column headings first before the looping starts
String [] headings = ("Order Id,Item ID,Item Name,Item Price,Item Count,Item Total,Paid Amount,VOID Order,Payment Method,Order Signature,Member/Authorization,Tab Number,Order Time").split(",");
writer.writeNext(headings);
for(CSVcursor.moveToFirst(); !CSVcursor.isAfterLast(); CSVcursor.moveToNext()) //Loop through all results (use row count of table)
{
String[] entries = (CSVcursor.getInt(CSVcursor.getColumnIndex("orderId"))+ ","
+CSVcursor.getInt(CSVcursor.getColumnIndex("itemId"))+ ","
+CSVcursor.getString(CSVcursor.getColumnIndex("itemName"))+ ","
+CSVcursor.getString(CSVcursor.getColumnIndex("itemPrice")) + ","
+CSVcursor.getInt(CSVcursor.getColumnIndex("itemCount"))+ ","
+CSVcursor.getString(CSVcursor.getColumnIndex("itemTotal"))+ ","
+CSVcursor.getString(CSVcursor.getColumnIndex("orderPaid"))+ ","
+CSVcursor.getInt(CSVcursor.getColumnIndex("orderVoid"))+ ","
+CSVcursor.getString(CSVcursor.getColumnIndex("orderType"))+ ","
+CSVcursor.getBlob(CSVcursor.getColumnIndex("orderSignature"))+ ","
+CSVcursor.getString(CSVcursor.getColumnIndex("referenceId"))+ ","
+CSVcursor.getInt(CSVcursor.getColumnIndex("orderTab"))+ ","
+CSVcursor.getString(CSVcursor.getColumnIndex("orderTime"))).split(","); //Split the string by the delimiter
writer.writeNext(entries); //Write current row of DB to file
writer.flush(); //Flush the stream
}
writer.close();
文件已成功写入,但当我查看 .csv 文件时,保存 blob 数据的列如下所示。
B@2342342 B@2123982 B@3952929
看起来我只是在保存文件的签名或其他一些属性,而不是文件本身。
我需要按位/缓冲区将 blob 流式传输到 csv 文件吗?
【问题讨论】:
-
更典型的解决方案是将图像另存为单独的文件。否则,您需要决定如何将 BLOB 列中的
byte[]转换为某种字符串表示形式,然后将字符串放入 CSV 文件中。
标签: android sqlite csv blob writer