gpt4 book ai didi

android - CSVReader 和安卓

转载 作者:行者123 更新时间:2023-11-29 00:32:17 25 4
gpt4 key购买 nike

我想从 csv 文件中读取数据并将其存储到数据库中。这就是我保存 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。

预先感谢您的帮助。

最佳答案

您的项目是在 Eclipse IDE 中吗?如果是,则查看是否在“项目属性->Java 构建路径->库”中设置了 lib (opencsv.jar) 并且在选项卡中检查了它:“Order and导出”也。在“订购和导出”下,将库移至列表顶部。然后清理并重建。

PS:如果这没有帮助,请提供错误的完整堆栈跟踪。

关于android - CSVReader 和安卓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14749189/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com