javaandroid-studiosavewekaarff

Where should I save my file in Android for local access?


I have two datasets which are currently in the same folder as my java files AND on my PC. Currently, I am accessing them through my C-drive. Since this is an app, where should I save my .ARFF files and what path should I use instead? I have tried in the raw folder, but nothing seems to work.

Here's what I have so far... Current Code Hierarchy


Solution

  • After too many hours

    A very easy solution to retrieving data from the assets folder! Only one user-defined method.

    1. Make raw folder in res directory.
    2. Paste whatever files in the raw directory
    3. Make a separate .java file
    4. Make sure it is a derivative class (in this case it extended AppCompatActivity
    5. Write Part A in the body
    6. Write Part B outside the body

    A. This is in the main function OR in a custom, user-defined function.

    BufferedReader bReader;            
    bReader = new BufferedReader(
               new InputStreamReader(ISR(R.raw.FILENAME_WITHOUT_TYPE)));
    

    FILENAME_WITHOUT_TYPE refers to only the name of the file, not its ending (everything followed by the .).

    B. This is the definition of ISR.

    public InputStream ISR(int resourceId) {
        InputStream iStream = getBaseContext().getResources().openRawResource(resourceId);
        return iStream;
    }
    

    Works like a charm!

    Resources: