【发布时间】:2015-02-03 15:18:13
【问题描述】:
我的资产文件中有一个 csv 文件,并希望使用 opencsv 读取它
我成功获取并读取了文件,但打印失败,
并且字符串显示为下面的屏幕截图。
我的 csv 从 excel 保存为 Unicode
我在读取和记录 csv 时的代码:
AssetManager assetManager = context.getAssets();
try {
InputStream csvStream = assetManager.open("data.csv");
InputStreamReader csvStreamReader = new InputStreamReader(csvStream);
CSVReader csvReader = new CSVReader(csvStreamReader);
String [] nextLine;
Log.d("test","reading csv");
while ((nextLine = csvReader.readNext()) != null) {
// nextLine[] is an array of values from the line
Log.d("test",nextLine.toString() + " etc...");
String[] temp= nextLine.toString().split(",");
for(int i=0; i<nextLine.length;i++){
Log.d("test", nextLine[i]);
}
break;
}
} catch (FileNotFoundException e) {
Log.d("test","fail read csv");
e.printStackTrace();
} catch (IOException e) {
Log.d("test","io exception csv");
e.printStackTrace();
}
csv 文件的文本
以及 logcat 中的屏幕截图:
【问题讨论】: