0
I am trying to check if a file exists in the application directory in the 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 check?
the
meu_diretório
has same accent or only example?– viana
It was just an example.
– Henqsan
Are you giving any error in the application?! Have you granted read or write permission?
– viana
I am using the permissions I included in the question. There is no error.
– Henqsan
Instead of
getPath()
you tried to usegetAbsolutePath()
?– viana
It didn’t work either!
– Henqsan
Let me understand! There is the file, but your application does not recognize right?! You came to debug and see if you are getting the path correctly?!
– viana
The path that is shown in the path is
storage/emulated/0/
but the right thing should bedata/br.com.minhaaplicacao/meu_diretorio/arquivo
or I’m confusing everything?– Henqsan