java无法从资产中读取csv文件
我正在尝试从安卓资产文件夹读取csv文件。我看过其他关于这个的帖子,看起来我和其他人一样设置了它。我已经尝试过this.getAssets()
并将上下文传递给该方法,然后使用context.getAssests()
这里是我用来读取文件的代码。并将信息存入数据库
try{
AssetManager mng = getApplicationContext().getAssets();
InputStream is = mng.open("word_types.csv");
CSVReader csv = new CSVReader(new InputStreamReader(is));
String[] s;
while((s = csv.readNext()) != null){
db.addWordType(Integer.parseInt(s[0]), s[1], Integer.parseInt(s[2]));
}
csv.close();
}catch(IOException ioe){
Log.e("File Read Error: ","" + ioe.getMessage());
}
for(int i=1;i<=12 ;i++ )
Log.i(i+" = ", ""+ db.getWordType(i));
以下是在logcat中打印的内容:
E/File Read Error: (25767): word_types.csv
I/1 = (25767): null
I/2 = (25767): null
I/3 = (25767): null
I/4 = (25767): null
I/5 = (25767): null
I/6 = (25767): null
I/7 = (25767): null
I/8 = (25767): null
I/9 = (25767): null
I/10 = (25767): null
I/11 = (25767): null
I/12 = (25767): null
# 1 楼答案
我意识到我犯了一个愚蠢的错误。谢谢CommonsWare告诉我这样打印stacktrace。我不知道把ioe作为第三个参数。查看stacktrace后,我意识到我把assets目录拼写错了。我有主张