title: Exporting multiple tables to multiple CSV files
body: <p>I have many tables in my <strong>database</strong> in the app. During the app use, these tables are created by the user and also their names.</p>
  
  <p>I would like to export all tables, each one to a single <strong>.CSV</strong> file with the table's name.</p>
  
  <p>For example, I have 3 tables named 1, 2 and 3. I would like to export and them create files 1.csv, 2.csv and 3.csv.</p>
  
  <p>I really appreciate some help, because I could not find any answer in the web.</p>
  
  <p>I am using some classes called CSVReader and CSVWriter, which are very popular.</p>
  
  <p>Here in my method to export. It does not show any error, but no file is exported:</p>
  
  <pre><code>public void exportTables (View view) {
      File dbFile = getDatabasePath("database.db");
      Banco dbhelper = new Banco(getApplicationContext());
      File exportDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
      if (!exportDir.exists()) {
          exportDir.mkdirs();
      }
  
      File file = new File(exportDir, tableName +".csv");
  
      try {
  
          file.createNewFile();
          CSVWriter csvWriter = new CSVWriter(new FileWriter(file));
          SQLiteDatabase db = dbhelper.getReadableDatabase();
          Cursor curCSV = db.rawQuery("SELECT * FROM sqlite_master WHERE type='table' AND name NOT LIKE 'android_metadata' AND name NOT LIKE 'sqlite_sequence'", null);
          csvWriter.writeNext(curCSV.getColumnNames());
  
          while(curCSV.moveToNext()) {
              // Table columns
              String arrStr[] ={curCSV.getString(0),curCSV.getString(1)};
              csvWriter.writeNext(arrStr);
          }
  
          csvWriter.close();
  
          curCSV.close();
      }
      catch(Exception sqlEx) {
          Log.e("MainActivity", sqlEx.getMessage(), sqlEx);
      }
  
      Toast.makeText(this, "FILE EXPORTED WITH SUCCESS!", Toast.LENGTH_SHORT).show();
  }
  </code></pre>