12

Is it possible for android application to create several directories in internal storage for storing there different kinds of files? I need this capability, because I'll need to delete a kind of files at definite time moment in my application.

When I try to use standard Context method openFileOutput() and send to it filename with "/" symbol I get IllegalArgumentException.

Tell me please what classes and methods could allow me such functionality?

teoREtik
  • 7,886
  • 15
  • 46
  • 65
  • http://stackoverflow.com/questions/8124612/android-create-folders-in-internal-memory/9707270#9707270 – StepanM Mar 14 '12 at 17:54
  • I had a similar problem. And resolved it. http://stackoverflow.com/questions/8124612/android-create-folders-in-internal-memory/9707270#9707270 – StepanM Mar 14 '12 at 17:54

1 Answers1

36

Use Context.getDir(String name, int mode) method to create or access directories in internal storage. Quote from docs:

Retrieve, creating if needed, a new directory in which the application can place its own custom data files. You can use the returned File object to create and access files in this directory. Note that files created through a File object will only be accessible by your own application; you can only set the mode of the entire directory, not of individual files.

UPD Example:

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.
Konstantin Burov
  • 68,980
  • 16
  • 115
  • 93
  • Thanks a lot for your responding. Could you explain me please. When I create the `File` object using `Context.getDir()`, how could I add to this `File` object another `File` object? – teoREtik Aug 18 '11 at 11:13