views:

399

answers:

2

I'm trying to save a file in a subdirectory in Android 1.5. I can successfully create a directory using

_context.GetFileStreamPath("foo").mkdir();

(_context is the Activity where I start the execution of saving the file) but then if I try to create a file in foo/ by

_context.GetFileStreamPath("foo/bar.txt");

I get a exception saying I can't have directory separator in a file name ("/").

I'm missing something of working with files in Android... I thought I could use the standard Java classes but they don't seem to work... I searched the Android documentation but I couldn't fine example and google is not helping me too...

I'm asking the wrong question (to google)...

Can you help me out with this?

Thank you!

+1  A: 

Use getDir() to get a handle on the "foo" directory as a File object, and create something like new File(fooDir, "bar.txt") from it.

Sean Owen
A: 

I understood what I was missing. Java File classes works just fine, you just have to pass the absolute path where you can actually write files.

To get this "root" directory I used _context.getFilesDir(). This will give you the root of you application. With this I can create file with new File(root + "myFileName") or as Sean Owen said new File(rootDirectory, "myFileName").

Davide Vosti