0

Following is my file write method in andriod. I want to know where my file is exactly written. I tried to find in my phone storage. But I cannot find. Please help me.

void writeFile(String file, String data, boolean append){
        try {
            FileOutputStream fos;

            if (append){
                fos = openFileOutput(file, Context.MODE_APPEND);            
            }
            else 
                fos = openFileOutput(file, Context.MODE_PRIVATE);
            fos.write(data.getBytes());
            fos.close();                
        } catch (Exception e) {
            e.printStackTrace();                
        }   
    }
ksh
  • 141
  • 1
  • 3
  • 16
  • You can try , getting absolute path of this file then check that file in your install app's dir. probably it's in your app's dir. – swiftBoy Nov 21 '13 at 08:12
  • it's inside data/data/com.myapp.exp/.. but I cannot find my app folder inside data/data. Is it hidden or something? – ksh Nov 21 '13 at 09:18

2 Answers2

0

Your file is written on the device's internal storage. By default, files saved to the internal storage are private to your application and other applications cannot access them (nor can the user). When the user uninstalls your application, these files are removed.

If you want to browse for the saved file on the phone storage, you have to write it on external storage (sd card, or build in storage). Here's an example how to write/read from external storage: Android how to use Environment.getExternalStorageDirectory()

Community
  • 1
  • 1
Andy Res
  • 15,963
  • 5
  • 60
  • 96
0

The parameter file is the path where your file located.

but sometimes you can't see it in your phone storage because of the permission.

You can open DDMS-File Explorer, Then when you tracking the path there is a 'Permissions' column where you can see if you have full access to a folder or a file.

Scott Zhu
  • 8,341
  • 6
  • 31
  • 38
  • it's inside data/data/com.myapp.exp/.. I used DDMS and I don't find anything inside data folder. – ksh Nov 21 '13 at 09:19
  • That's the problem! You do not have full access to the data/ folder, that's why you can't see the file. You need to change the permission of the folder first. – Scott Zhu Nov 21 '13 at 10:39
  • To change the permission of the data/ folder, i think you need to root your device first. There is an app called ES file browser which allows you do both root and change permission of a folder. – Scott Zhu Nov 21 '13 at 10:44