csciBeginner csciBeginner - 1 year ago 39
Java Question

Accessing Data Saved to Internal Storage on Android Device

I am new to Android Studio and have gone through a ton of tutorials. I have a working accelerometer and want to save the data to a .csv file.
My code below works because when I use the emulator I am able to export the .csv file , with the correct data, to my desktop and open it. I have these two permissions in my


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

When I go into the file explorer on my device using apps such as Astro or ES and go to
I do not even see my package there even though the app works on my phone. Is there something you need to do to have the package show up in the file explorer? I would like to get the data from the .csv from my phone.

I was hoping someone had some in

String Entry = x.getText().toString() + ", "
+ y.getText().toString() + ", " +
z.getText().toString() + "\n";
FileOutputStream outPut = openFileOutput(FILENAME, Context.MODE_APPEND);
}catch(Exception err){


String dir = Environment.getExternalStorageDirectory().getAbsolutePath();
String FILENAME = "keyboardTest.csv";
File file = new File (dir, FILENAME)
try {
FileOutputStream out = new FileOutputStream(file, true);
} catch (Exception err) {

Now I am able to access the file on my phone

Answer Source

You can't access these files(inside /data/data) until you are running the app on an emulator or you are running the app on a rooted device.

please check this for more details.


You can do the following to save files in an accessible location:-

/*get the path to internal storage*/
File path = Environment.getExternalStorageDirectory();
/*create the app folder and check if it exists or not*/
File curDir = new File(path.getAbsolutePath()+"/"+appName);
/*create the file*/
File f = new File(curDir+"/"+fileName);
/*code to edit the file*/