Mutti February 2016

How to get a specific column value from multile column from CSV file in ANDROID

I am trying to get values from csv file but getting ERROR file Not found. I am new with android programming. I've tried CSVReader but getting same error. I Tried these methods

            try {
                    mng = getApplicationContext().getAssets();
                    test = mng.open("test.csv");
                    reader = new BufferedReader(newInputStreamReader(test));

                    for(L=0;((nextLine = reader.readLine()) != null);L++){

                         String[] cols = nextLine.split(",");
                         b[L]=cols[0];
                         m[L]=Integer.parseInt(b[L]);                        
                         }
                    Arrays.sort(m);
                } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }

Logcat error:

02-08 17:55:22.314: I/dalvikvm(2856): Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations 02-08 17:55:22.314: W/dalvikvm(2856): VFY: unable to resolve virtual method 411: Landroid/content/res/TypedArray;.getChangingConfigurations ()I 02-08 17:55:22.314: D/dalvikvm(2856): VFY: replacing opcode 0x6e at 0x0002 02-08 17:55:22.314: I/dalvikvm(2856): Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType 02-08 17:55:22.314: W/dalvikvm(2856): VFY: unable to resolve virtual method 433: Landroid/content/res/TypedArray;.getType (I)I 02-08 17:55:22.314: D/dalvikvm(2856): VFY: replacing opcode 0x6e at 0x0002 02-08 17:55:22.354: I/dalvikvm(2856): Could not find method android.content.res.Resources.getDrawable, referenced from method android.support.v7.internal.wi

Answers


AKSiddique February 2016

To read data from internal storage you need your app files folder and read content from there:

String yourFilePath = context.getFilesDir() + "/" + "hello.txt";
File yourFile = new File( yourFilePath );

Also you can use this approach:

   FileInputStream fis = context.openFileInput("hello.txt", Context.MODE_PRIVATE);
   InputStreamReader isr = new InputStreamReader(fis);
   BufferedReader bufferedReader = new BufferedReader(isr);
   StringBuilder sb = new StringBuilder();
   String line;
   while ((line = bufferedReader.readLine()) != null) {
       sb.append(line);
   }

Post Status

Asked in February 2016
Viewed 1,762 times
Voted 10
Answered 1 times

Search




Leave an answer