0

I've been struggling to create a CSV file from my app. Here's my code:

private void createFile() throws IOException {
        Log.i("test", "creating file");
        file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "/test.csv");
        if (!file.createNewFile()) {
            Log.i("test", "file doesn't exist");
            try {
                Log.i("test", "gonna create the new file");
                Log.i("test", "done :)");
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        if (!file.exists()) {
            Log.i("test", "Oh no");
            return;
        }
}

The Logcat prints:

creating file file doesn't exist gonna create the new file Oh no

I don't know why file.createNewFile() returns false yet when I check if it exists, it also returns false.

I have my permissions declared in my Manifest and enabled storage permissions from settings as well.

I also have a function that checks if I have storage perms and it says that I do.

shiho
  • 31
  • 1
  • 5

0 Answers0