mercredi 23 mars 2016

Android CSV import issue

I am trying to read a CSV file into my SQLite database. I am currently useing a button to run the method as I am not sure where to call it so it will load the data when the app is launched. When I call it in the on create of my launch screen there is an issue.

This is the error.

Caused by: java.io.FileNotFoundException: C:/Users/b00619342/Downloads/VegT(DBCodedNeedPreSetD)/app/src/main/assets/brekfasttable.csv: open failed: ENOENT (No such file or directory)

Heres the code

public void brekCSV() throws IOException {

    String[] row = null;
    //need to change when the project is moved to a new location
    String csvBrek = "C:/Users/b00619342/Downloads/VegT(DBCodedNeedPreSetD)/app/src/main/assets/brekfasttable.csv";

    SQLiteDatabase db = getWritableDatabase();

    BufferedReader br = new BufferedReader(new FileReader(csvBrek));

    String line;
    while ((line = br.readLine()) != null) {
        String[] tokens = line.split(",(?=([^\"]*\"[^\"]*\")*[^\"]*$)", -1);

        db.execSQL("INSERT INTO " + TABLE_BREK +
                "VALUES(" + tokens[0] + "," + tokens[1] + "," + tokens[2] + "," + tokens[3] + "," + tokens[4] + "," + tokens[5] + "," + tokens[6] + ")");
    }

    db.close();

}//end of brekCSV

Aucun commentaire:

Enregistrer un commentaire