How to check if file exists in the application directory in internal storage?

0

I'm trying to check if a file exists in the application directory in internal storage with the code below

String path = Environment.getExternalStorageDirectory().getPath()+"/meu_diretorio/arquivo";
    boolean exists = (new File(path)).exists();
    if (!exists) {
        Toast.makeText(getActivity(), "O arquivo não existe!", Toast.LENGTH_SHORT).show();
    }else{
        Toast.makeText(getActivity(), "O arquivo existe!", Toast.LENGTH_SHORT).show();
    }

I'm using the permissions:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

However it is not working. How should I proceed with this verification?

    
asked by anonymous 20.08.2017 / 00:41

1 answer

1

The code you are using is for accessing the external store.

If you want to get the path to the internal storage root you should use File getFilesDir () . To get the full path to a name file, stored in the internal storage , use File getFileStreamPath (String name)

Notes:

20.08.2017 / 15:59