Monday, May 2, 2011

Using Java File Handler API vs Android File handler API

I had an application App1 whose package name was "com.sample".

I decided to create a directory called "testdirectory" under "data/data/com.sample" so that it's path would be "data/data/com.sample/testdirectory".

So, I wrote a code like this:

File dir = getDir("testdirectory", Context.MODE_WORLD_WRITEABLE);


But what I got was :
data/data/com.sample/app_testdirectory
getDir() is Android API.

So I decided to try out java File handler:

File dir = new File("data/data/com.sample/testdirectory").mkdir();

This created "data/data/com.sample/directory" without prefixing with the word "app_".
So while Android's getDir() always prepends the word to the "app_" to the directory name, Java file handlers allows to create a directory without prefixing anything !

No comments:

Post a Comment