You can use getFileStreamPath() instead of getDataDir(), if you just
want a place to put directories. In a future SDK there will be a new
set of APIs explicitly for creating directories.
On Jan 16, 11:52 am, oxonom <phyrum....@sign.ch> wrote:
I want to create a directory in file system, I run the following code,
but failed:
try {
File dir = getFileStreamPath("mydir1");
if (!dir.mkdirs()) {
Log.e(TAG, "Create dir in local failed"); //<--
print this error
return;
}
} catch (FileNotFoundException e1) {
Log.e(TAG, "error 1: "+e1.toString());
}
Could you help me to check what's wrong with me?
Thank you.
On Jan 17, 10:09 am, hackbod <hack...@gmail.com> wrote:
> You can use getFileStreamPath() instead of getDataDir(), if you just
> want a place to put directories. In a future SDK there will be a new
> set of APIs explicitly for creating directories.
> On Jan 16, 11:52 am, oxonom <phyrum....@sign.ch> wrote:
> > well, while looking in the docs, getDataDir is only temporary :-(
> > it's so easy with Eclipse to type get+[CTRL+SPACE] and using the first
> > suitable method.
> > On 16 Jan., 20:39, trickybit <jmack...@gmail.com> wrote:
> > > blast, I screwed that up.
> > > I meant getFileStreamPath( "my/directory/name" ).mkdirs()
> > > seems equivalent to what you provided.
> > > On Jan 16, 11:11 am, oxonom <phyrum....@sign.ch> wrote:
> > > > short answer: yes
> > > > here is an example:
> > > > new File(getDataDir() +"/mydirectory").mkdirs();
> I want to create a directory in file system, I run the following code,
> but failed:
> try {
> File dir = getFileStreamPath("mydir1");
> if (!dir.mkdirs()) {
> Log.e(TAG, "Create dir in local failed"); //<--
> print this error
> return;
> }
> } catch (FileNotFoundException e1) {
> Log.e(TAG, "error 1: "+e1.toString());
> }
> Could you help me to check what's wrong with me?
> Thank you.
> On Jan 17, 10:09 am, hackbod <hack...@gmail.com> wrote:
> > You can use getFileStreamPath() instead of getDataDir(), if you just
> > want a place to put directories. In a future SDK there will be a new
> > set of APIs explicitly for creating directories.
> > On Jan 16, 11:52 am, oxonom <phyrum....@sign.ch> wrote:
> > > well, while looking in the docs, getDataDir is only temporary :-(
> > > it's so easy with Eclipse to type get+[CTRL+SPACE] and using the first
> > > suitable method.
> > > On 16 Jan., 20:39,trickybit<jmack...@gmail.com> wrote:
> > > > blast, I screwed that up.
> > > > I meant getFileStreamPath( "my/directory/name" ).mkdirs()
> > > > seems equivalent to what you provided.
> > > > On Jan 16, 11:11 am, oxonom <phyrum....@sign.ch> wrote:
> > > > > short answer: yes
> > > > > here is an example:
> > > > > new File(getDataDir() +"/mydirectory").mkdirs();
It turns out that getFileStreamPath() will not accept path separators
in its argument.
But:
1- the above approach works to create a single-depth subdirectory
(i.e., no slashes).
2- if you want to create deeper subdirectory trees, you can do this:
File subdirectory = null;
try {
File basedirectory = getFileStreamPath( "basedir" );
subdirectory = new File( basedirectory, "subdir_0/
subdir_1" );
if ( ! subdirectory.exists() ) {
Log.i( LOGTAG, "attempt to create subdirectory: " +
subdirectory );
subdirectory.mkdirs(); // makes all subdir levels you need
}
}
catch ( FileNotFoundException e1 ) {
Log.e( LOGTAG, "oops 0", e1 );
}
This will create a subdirectory named (in the current SDK)
/data/data/<package>/files/basedir/subdir_0/subdir_1
If you provide an empty string to the first getFileStreamPath() call,
you will get
/data/data/<package>/files/subdir_0/subdir_1
but I'm not sure I'd want to rely on that behavior.
Jim
On Jan 16, 11:39 am, trickybit <jmack...@gmail.com> wrote:
Thank you, I already updated my source code. In my example, I unpack a
zip file from the apk resource folder to the local application folder
so I can display the html pages with WebKit/WebView.
I too used an empty string to get the files folder.
> It turns out that getFileStreamPath() will not accept path separators
> in its argument.
> But:
> 1- the above approach works to create a single-depth subdirectory
> (i.e., no slashes).
> 2- if you want to create deeper subdirectory trees, you can do this: