title: Android - Importing multiple .CSV Files to multiple tables in SQLite database
body: <p>I have in my Android device a folder with multiple .CSV files.</p>
  
  <p>I want to import all of them to my SQLite Database, but each file must be a different table.</p>
  
  <p>All .CSV file are simple. They have just one column.</p>
  
  <p>Example:</p>
  
  <p><strong>File.CSV</strong></p>
  
  <pre><code>12345
  
  123
  
  00000000
  </code></pre>
  
  <p><strong>AnotherFile.CSV</strong></p>
  
  <pre><code>XXXXX
  
  ZZZZZZZZZZ
  
  FFFF
  </code></pre>
  
  <p>Here is my method and it is not working. I could not understand why:</p>
  
  <pre><code>@TargetApi(Build.VERSION_CODES.M)
  public void importaTabelas() {
  
      //Check the read permission
      if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
  
          try {
  
              //Check if the folder exists
              File importDir = new File (Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/ENEL/IMPORTADOS/");
              if (!importDir.exists())
              {
                  importDir.mkdirs();
              }
  
              //Read all file names
              for (File f : importDir.listFiles()) {
  
                  if (f.isFile()) {
  
                      //Put the files names into variable nomeArq
                      nomeArq = f.getName();
  
                      //Take off the file extension .csv
                      if (nomeArq.indexOf(".") &gt; 0)
                          nomeArq = nomeArq.substring(0, nomeArq.lastIndexOf("."));
  
                      SQLiteDatabase db = this.banco.getWritableDatabase();
  
                      try {
  
                          //Create table with the name of the .csv file
                          String criaTab = "CREATE TABLE IF NOT EXISTS " + nomeArq +  " (id integer PRIMARY KEY AUTOINCREMENT, codigo varchar (50))";
                          db.execSQL(criaTab);
                          db.close();
  
                      } catch (SQLException e) {
                          e.printStackTrace();
                      }
  
                      //String for the file location
                      String fn = importDir + "/" + nomeArq + ".csv";
  
                      //Reads the file
                      FileReader fileReader = new FileReader(fn);
  
                      BufferedReader buffer = new BufferedReader(fileReader);
  
                      //ContentValues contentValues = new ContentValues();
  
                      String line = "";
  
                      //db.beginTransaction();
  
                      while ((line = buffer.readLine()) != null) {
  
                          //String[] colums = line.split("\t");
  
                          //String[] colums = line.split(";");
  
                          Toast.makeText(this, line, Toast.LENGTH_SHORT).show();
  
                          //contentValues.put("codigo", line);
  
                          //db.insert(nomeArq, null, contentValues);
  
                          db.execSQL("INSERT INTO " + nomeArq +  " (codigo) VALUES ('" + line + "')");
  
                      }
  
                      //db.setTransactionSuccessful();
                      //db.endTransaction();
  
                  }
  
              }
  
          } catch (Exception e) {
  
              Toast.makeText(this, "Catch!", Toast.LENGTH_SHORT).show();
              e.printStackTrace();
  
          }
  
      }
  
      else {
  
          requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 1);
  
      }
  
  }
  </code></pre>
  
  <p>Would you help me to make it works? Thanks!</p>