首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CSVReader和安卓

CSVReader和安卓
EN

Stack Overflow用户
提问于 2013-02-07 18:45:05
回答 1查看 1.2K关注 0票数 2

这就是我保存csv文件的方法(这是没有错误的-只是为了显示我计划用CSVreader读取的文件存储在哪里以及如何存储):

代码语言:javascript
复制
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文件的代码如下:

代码语言:javascript
复制
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。

提前感谢您的帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-02-07 19:00:16

您的项目是否在Eclipse IDE中?如果是,则查看是否在“项目属性->Java Build Path->Libraries”中设置了库(opencsv.jar),并在选项卡中选中了:"Order and Export“。在"Order and Export“下,将lib移到列表的顶部。然后进行清理和重建。

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14749189

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档