2

Inside onCreate() I have this line:

File aux = context.getFilesDir();

which outputs this:

/data/user/0/com.example.tirengarfio.myapplication/files

but.. where is this path exactly insde Linux filesystem? or is it taking as reference the Android Studio Project root directory? os should I create it somewhere?

EDIT:

As I said to @Simas, but by the moment Im not connecting any smartphone. Im just using emulators on Linux. My intention is just reading a file using

FileOutputStream fos = openFileInput(FILENAME, Context.MODE_PRIVATE);.

So, where should I place the file inside the Linux filesystem?

tirenweb
  • 30,963
  • 73
  • 183
  • 303
  • 1
    it is on your device, under `/data/user`. Not on Android Studio, not in the pc running linux – Blackbelt Oct 12 '15 at 20:10
  • "My intention is just reading a file using" -- `openFileOutput()` is for writing, not reading. "So, where should I place the file inside the Linux filesystem?" -- you don't. You write to that path first. Later on, you can read from it. – CommonsWare Oct 12 '15 at 20:28
  • @CommonsWare ok, thanks!, so in case I want to use `openFileInput()` directly (without using `openFileOutput()`), where should I place the file inside the Linux system? – tirenweb Oct 12 '15 at 20:39
  • Again, you don't. `getFilesDir()` will return varying locations based upon Android version, user account (primary versus secondary), and device specifics. The "Linux filesystem" in question is on the device or emulator; `getFilesDir()` does not map to any directory on your development machine. – CommonsWare Oct 12 '15 at 20:45
  • @CommonsWare so you mean that for an app that is reading or writing files (for example to send them to a server), and check that my code is ok, I must run the app on a smartphone, because there is no way to check reading or writing files on an emulator. I'm starting to create apps, but it seems it is more confortable to run the apps on the emulator, even if I connect easily the smartphone to my USB port and run them, or am I wrong? – tirenweb Oct 12 '15 at 22:26
  • @ziiweb: Emulators and devices are not significantly different with respect to what I have described. USB ports have nothing to do with what I have described. Your question is about [internal storage](https://commonsware.com/blog/2014/04/07/storage-situation-internal-storage.html); USB ports at most are involved with [external storage](https://commonsware.com/blog/2014/04/08/storage-situation-external-storage.html). – CommonsWare Oct 12 '15 at 22:31
  • You're welcome to try poking around an emulator (not a device) to find files on internal storage. They used to be in `/data/data/your.application.id.here/files`. I haven't gone looking there in quite some time, and that location could easily be wrong on newer versions of Android. – CommonsWare Oct 12 '15 at 22:31

2 Answers2

1

This is the path of your app's local data folder. It can either be in the memory card or the device storage.

There's no easy way to access it if your device is not rooted but here's a starter:
How to access data/data folder in Android device?

Community
  • 1
  • 1
Simas
  • 43,548
  • 10
  • 88
  • 116
  • Thanks @Simas, but by the moment Im not connecting any smartphone. Im just using emulators. My intention is just reading a file using `FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);`. Where should I place the file inside the Linux filesystem? – tirenweb Oct 12 '15 at 20:13
  • 1
    You don't place your file "inside the linux filesystem" when saving a file. You just choose whether to save it in internal storage or external storage, and the Android OS has standard directories for each of those areas. You don't have to like, pick the folder from the root of the device and put it somewhere. Your app already has designated areas on the disk to store its data. – NoChinDeluxe Oct 12 '15 at 20:26
0

Let us see what the doc says :

Returns the absolute path to the directory on the filesystem where files created with openFileOutput(String, int) are stored. No permissions are required to read or write to the returned path, since this path is internal storage.

So actually the files you will find are those which were saved with the very same function openFileOutput(String,int) by your/other applications.

So basically if you want to test some functionality (which I suppose) write a unit test that uses this API openFileOutput(String,int) to store some mockup data and then get it again with Context.getFilesDir() and some code for file processing.