簡體   English   中英

無法從資產讀取CSV文件

[英]Unable to read csv file from assets

我正在嘗試從android資產文件夾中讀取一個csv文件。 我已經查看了有關此內容的其他帖子,似乎我已經像其他人一樣設置了它。 我已經嘗試過this.getAssets()並將上下文傳遞給方法並使用context.getAssests()這是我用來讀取文件的代碼。 並將信息放入數據庫中。

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

我意識到自己犯了一個愚蠢的錯誤。 感謝CommonsWare告訴我有關像這樣打印出stacktrace的信息。 我不知道將ioe作為第三個參數。 查看stacktrace之后,我意識到我拼寫了資產目錄錯誤。 我有資產

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM