I want to make a folder in the Internal Memory in my application to store Audio Files,then check if the exist to do some operations. How to make this folde, in which path, and how to retrieve these files again?
Asked
Active
Viewed 2.1k times
1 Answers
12
File mydir = context.getDir("mydir", Context.MODE_PRIVATE); //Creating an internal dir;
File fileWithinMyDir = new File(mydir, "myfile"); //Getting a file within the dir.
FileOutputStream out = new FileOutputStream(fileWithinMyDir); //Use the stream as usual to write into the file
For deleting a file from internal :
if (new File("path/to/file").delete()) {
// Deleted
} else {
// Not deleted
}

iSun
- 1,714
- 6
- 28
- 57
-
1thanx ..i tried it,and i saw the path in the Log(/data/data/com.packageName/app_mydir/audio.mp3) But i want to play the audio but it keep showing me this error(android.media.MediaPlayer.prepare(Native Method)) in the prepare Method – Reham Dec 13 '11 at 18:56
-
if(mp==null){ mp = new MediaPlayer(); try { mp.setDataSource("/data/data/com.packageName/app_mydir/audio.mp3"); } catch (IllegalArgumentException e) { } if(mp != null && !mp.isPlaying()){ try { mp.prepare(); } – Reham Dec 13 '11 at 19:00
-
-
yeh...and by the way how can i delete these files from the memory if i won't use them anymore? – Reham Dec 13 '11 at 19:44
-
1i found this solution...and it works fine...:) http://stackoverflow.com/questions/4833777/android-playing-resource-files-from-internal-storage-causes-mediaplayer-prepare but i wanna know how can i delete these files? – Reham Dec 13 '11 at 20:00
-
Thanks alot Ali..:) But do you know how can i check if the media file reach the end ?? – Reham Dec 16 '11 at 15:47
-
What if I wanted to create a folder on application (only the first time). When saving the file, I would like to create a subfolder inside the already created folder. For example: On application load, I would like to create `com.mycompany.myapp` folder. Then, I would like to create another folder inside that, so, `com.mycompany.myapp\Folder1` and then `com.mycompany.myapp\Folder2` and so forth. Or is it recommended to create separate folder and not sub folder? – Si8 Sep 28 '16 at 19:43