CSVReader和android [英] CSVReader and android
问题描述
我想从CSV文件中的数据读取并存储到数据库中。这是我如何保存在CSV文件(这工作没有错误 - 只是为了显示在何处以及如何将文件保存在我计划CSVreader阅读):
I want to read in the data from a csv-file and store it into a database. This is how I saved the csv-file (this works without errors - just to show where and how the file is stored which I plan to read with CSVreader):
synchronized public void readFromUrl(String url, String outputFile, Context context) throws FileNotFoundException {
URL downloadLink = null;
try {
downloadLink = new URL(url);
} catch (MalformedURLException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
BufferedReader in = null;
try {
in = new BufferedReader(
new InputStreamReader(downloadLink.openStream(), "UTF8"));
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
FileOutputStream fstream = context.openFileOutput(outputFile,Context.MODE_PRIVATE);
Writer out = new OutputStreamWriter(fstream);
Log.d(TAG, "BufferedReader "+in);
String inputLine = null;
try {
while ((inputLine = in.readLine()) != null){
out.write(inputLine+"\n");
//logger.debug("DOWNLOADED: "+inputLine);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
fstream.close();
out.close();
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
我的code,到目前为止读取csv文件:
My code so far for reading the csv file:
public void readInCSVFile(String filename, Context context) throws IOException {
IDbHelper dbHelper = new DbHelper(); ;
CSVReader products = null;
products = new CSVReader(new InputStreamReader(context.getAssets().open(filename)));
我得到的NoClassDefFoundError异常。
I get a NoClassDefFoundError exception.
我在我的Android项目的参考库opencsv.jar。
I have the opencsv.jar in the Referenced libraries of my android project.
在此先感谢您的帮助。
推荐答案
是您在Eclipse IDE的项目?如果是的话,再看看是否LIB(opencsv.jar)被设定在项目属性 - > Java构建Path->库的和的,它是在该选项卡检查:订单和出口过。在排序和导出移动lib添加到列表的顶部。
那么干净,重建家园。
Is your project in the Eclipse IDE? If yes, then have a look whether the lib (opencsv.jar) is set in the "project properties->Java Build Path->Libraries" and that it is checked in the tab: "Order and Export" too. Under "Order and Export" move the lib to the top of the list. Then clean and rebuild.
PS:如果这样没有帮助,那么请提供错误的完整堆栈跟踪
PS: If this does not help, then please provide the complete stacktrace of the error.
这篇关于CSVReader和android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!