tags:

views:

45

answers:

1

I am trying to read a csv file from assets/file.csv, but the log keeps spitting out that it doesn't exist. Is my path correct for internal file storage? This is the class file:

package com.xxx.view;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;

public class ReadList {

    public String[][] mainMenuList() throws IOException {

        String [][] arrayList = new String [24][24];

        File file = new File("/data/data/com.xxx.view/file.csv");

        BufferedReader bufRdr  = new BufferedReader(new FileReader(file));
        String line = null;
        int row = 0;
        int col = 0;

        while((line = bufRdr.readLine()) != null && row < 24) { 

            StringTokenizer st = new StringTokenizer(line,",");

            while (st.hasMoreTokens()) {

                arrayList[row][col] = st.nextToken();
                col++;

            }

            col = 0;
            row++;

        }

        return arrayList;

    }

}
+1  A: 

Android doesn't let you access files on the phone's storage that way. You can only access files on the SD card via a traditional java File interface. Check out the AssetManager docs for more information. Also, check out this SO post for a similar example.

Chris Thompson