Red Virus Red Virus - 23 days ago 12
Android Question

Get Internal Storage custom directory location

I' am trying to get the location of my Internal Storage dynamically but having issues with it. The following is my code that am currently working with:

Context context = this;
File dir = context.getDir("appdata", Context.MODE_PRIVATE);
File file = new File(dir, "name.txt");
System.out.println( file.toString() );


The return path from the print is
/data/data/com.example.application.form/app/name.txt
but I want
Internal Storage/appdata/name.txt


What am I doing wrong?

Answer

use

File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath());

instead

File dir = context.getDir("appdata", Context.MODE_PRIVATE);
Comments