0

I am trying this simple save .txt on an Android phone but I can't find the file with ddms->file explorer; Data folder is empty/not expandable (so data/data/[package name]/files is not shown). Also on my Android device (moto G) I can't find the file. But the log shows the file should be saved :

saveBtn.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {

            // Create a file in the Internal Storage

            String fileName = "MyFile.txt";
            String content = "hello world";

            FileOutputStream outputStream = null;
            try {
                storageDir = new File(
                    Environment.getExternalStoragePublicDirectory(
                            Environment.DIRECTORY_PICTURES
                    ),
                    getAlbumName()
            );
                outputStream = openFileOutput( fileName, Context.MODE_PRIVATE);
                outputStream.write(content.getBytes());
                outputStream.close();

                Log.d(SAVE_PROCESS, "File directory: "+storageDir +" File name: "+fileName + " directory "+getFilesDir());
            } catch (Exception e) {
                e.printStackTrace();
                Log.d(SAVE_PROCESS, "File not saved");
            }

        }
    });
}
Misha Akopov
  • 12,241
  • 27
  • 68
  • 82
alex
  • 4,804
  • 14
  • 51
  • 86

3 Answers3

1

I also had same problem. I think your file is in below path. In eclipse :- Open File Explorer -> mnt -> shell -> emulated -> 0 -> DIRECTORY_PICTURES.

I hope this answers your question.

Mohammad Tauqir
  • 1,817
  • 1
  • 18
  • 53
0

App private directory /data/data/[package name] is accessible to your app only, but it's not accessible to other apps, and it's generally NOT accessible from ADB/DDMS/through your phone USB port.

If you root your phone, or install an engineering build of Android, you can run command adb root from PC, or command stop adbd; setprop service.adb.root 1; start adbd from root shell on Android, this will restart ADB with root permissions, then you will be able to access directories under /data/data.

Or just save your file to SD card, it's accessible from everywhere.

pelya
  • 4,326
  • 2
  • 24
  • 23
0

You are saving the file in the Public external folder for images, not in your app folder (which cannot be accessed, as already answered). You should check in a path like /storage/emulated/legacy/Pictures (might be slightly different depending on your phone)

Sebastian
  • 1,076
  • 9
  • 24