这就是我保存csv文件的方法(这是没有错误的-只是为了显示我计划用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();
}
}到目前为止,我用于读取csv文件的代码如下:
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异常。
我在我的android项目的引用库中有opencsv.jar。
提前感谢您的帮助。
发布于 2013-02-07 19:00:16
您的项目是否在Eclipse IDE中?如果是,则查看是否在“项目属性->Java Build Path->Libraries”中设置了库(opencsv.jar),并在选项卡中选中了:"Order and Export“。在"Order and Export“下,将lib移到列表的顶部。然后进行清理和重建。
PS:如果这没有帮助,那么请提供错误的完整堆栈跟踪。
https://stackoverflow.com/questions/14749189
复制相似问题