Accumulate the database used on SQLite at least somewhere.



  • The second day is impossible to complete the elementary: to copy this invisible file. Here's the code:

    if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
                {
                    Toast.makeText(getApplicationContext(),
                            "SD-карта не доступна: " + Environment.getExternalStorageState(),
                            Toast.LENGTH_LONG).show();
                }
                else
                {
                    Toast.makeText(getApplicationContext(),
                            "SD-карта доступна: " + Environment.getExternalStorageState(),
                            Toast.LENGTH_LONG).show();
                    // получаем путь к SD
                    File sdPath = getExternalFilesDir(null);
                    // добавляем свой каталог к пути
                    sdPath = new File(sdPath.getAbsolutePath());
                    // создаем каталог
                    if (!sdPath.exists())
                    {
                        sdPath.mkdirs();
                        Toast.makeText(getApplicationContext(), "создали папку", Toast.LENGTH_LONG).show();
                    }
                    try
                    {
                        // открываем потоки для записи
                        File fFrom = new File(this.getDatabasePath("DBtimes.db").getAbsolutePath(), "DBtimes.db");
                        File fTo = new File(sdPath, "CH_" + s_now + ".db");
                        InputStream in = new FileInputStream(fFrom);
                        OutputStream out = new FileOutputStream(fTo);
                        byte[] buf = new byte[1024];
                        int len;
                        while ((len = in.read(buf)) > 0)
                        {
                            out.write(buf, 0, len);
                        }
                        // Закрываем потоки
                        in.close();
                        out.close();
                        Toast.makeText(getApplicationContext(),
                                s_now + "копируем файл    ",
                                Toast.LENGTH_LONG).show();
    
                }
                catch (FileNotFoundException ex)
                {
                    Toast.makeText(getApplicationContext(), "не нашли файл", Toast.LENGTH_LONG).show();
    
                }
                catch (IOException e)
                {
                    Toast.makeText(getApplicationContext(), "другая ошибка", Toast.LENGTH_LONG).show();
    
                }
    

    That I didn't write here:

    File fFrom = new File(this.getDatabasePath("DBtimes.db").getAbsolutePath(), "DBtimes.db");

    and

    File fFrom = new File("/data/data/имя_пакета/databases/DBtimes.db");

    and simple.

    File(getDatabasePath("DBtimes.db").getAbsolutePath(), "DBtimes.db");

    and with an expansion of .db and without, and an open base, tried and closed.
    It also fails to:

    File fFrom = new File(getApplicationContext().getDatabasePath("DBtimes.db").getAbsolutePath(), "DBtimes.db");

    a

    Сontext.getDatabasePath("DBtimes.db").getAbsolutePath();

    The word Sontext, or in another case, says,
    Insufficient getDatabasePath( "DBtimes.db") cannot be applied to static Sontext.
    What's wrong?



  • I've found a much more banal way out: direct reference to the address, but with two cosmic features.

     File fFrom = new File("//data/data/имя_пакета/databases/", "DBtimes");
    

Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2