2
我正尝试从android资源文件夹读取csv文件。我已经看过其他帖子,似乎我已经建立了与其他人一样。我已尝试this.getAssets()
并将上下文传递给该方法并使用context.getAssests()
以下是我用于读取该文件的代码。并将这些信息放入数据库中。无法从资产中读取csv文件
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
将'ioe'作为第三个参数传递给你的'Log.e()'调用,所以你可以看到完整的堆栈跟踪。 – CommonsWare 2013-03-21 18:39:21
谢谢。不知道这一点。 – Zabador 2013-03-21 19:07:01