Edit csv file using Excel without reformatting in android

I am trying to make a simple android app that basically imports the csv and inserts it into a custom Array list. So far, I was able to read the csv file when I did not update the content of the CSV file. I found that when I update the CSV file, excel changes the formula of the csv file.
     Here is my code to read the csv file:

     selectedFile = new File(data.getStringExtra(FilePicker.EXTRA_FILE_PATH));
         ArrayList<Expense> objList= new ArrayList<>();
       String file=selectedFile.getPath();

      FileInputStream fileInputStream = null;
      try {
             fileInputStream = new FileInputStream(new File(selectedFile.getPath()));
           } catch (FileNotFoundException e) {
                   e.printStackTrace();
                        }


        BufferedReader reader = null;
     reader = new BufferedReader(new InputStreamReader(fileInputStream, Charset.forName("UTF-8")));

             String line = "";
                        StringTokenizer st = null;
                        try {

                            while ((line = reader.readLine()) != null) {
                                st = new StringTokenizer(line, ",");
                                ExpenseShare obj= new ExpenseShare ();
                                //your attributes
                                obj.setAmount(st.nextToken());
                                obj.setName(st.nextToken());
                                obj.setDate(st.nextToken());
                                obj.setTime(st.nextToken());
                                objList.add(obj);

                                Log.e("latasingh"," "+obj.getName()+" "+(obj.getAmount())+" "+obj.getDate()+" "+ obj.getTime()); //I understood this problem by seeing log data.
                            }
                        } catch (IOException e) {

                            e.printStackTrace();
                        }

      

How can I solve this problem. Thank!

+3


source to share





All Articles