简体   繁体   中英

Where is my file stored while I write file using FileOutPutStream?

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();                
        }   
    }

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()

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM