What is the correct way to put the address inside the Path?

Asked

Viewed 50 times

1

Because I am unable to locate my.txt file. Follow the code:

public void criatxt() {

    String texto = "XXX";

    try {
        String filePath = this.getFilesDir().getPath().toString()
                + "/meuarquivo.txt";
        File f = new File(filePath);
        PrintWriter arq = new PrintWriter(f);
        System.out.println("Salvou");
        arq.print(texto);
        arq.close();
    } catch (Exception er) {
        er.printStackTrace();
        System.out.println("Salvou: " + er.getStackTrace());
    }
}

Thank you in advance!

  • By recording in this folder you will not be able to see it yourself, this folder is only accessible by the application itself. Try writing to a public folder (Internal Storage) or to the memory card (Xternal Storage). Then I’ll draw up an answer, while you’re at it: http://stackoverflow.com/questions/31220476/android-write-to-internal-storage

  • vlw man, I realized that this my code recorded on the date/date of Android and I ended up getting it from there anyway, but it is learning for when I do not have access to the date, when using the mobile as device. vlw!

1 answer

1

Use

File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);

To get the way of android download folder, so it will be easy for you to find your saved files.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.