Recursive directory creation fails on device
My code runs in the simulator, but crashes on Android with a FileNotFoundException
as it tries to FileSystemStorage#openOutputStream
in an non-existing directory. I create all the needed directories recursively before using
private void ensureParentDirs(String file)
final int j = file.lastIndexOf("/");
final String s = file.substring(0, j);
if (storage.isDirectory(s)) return;
storage.mkdir(s);
if (storage.isDirectory(s)) return;
ensureParentDirs(s);
storage.mkdir(s);
if (storage.isDirectory(s)) return;
Log.p("Cannot create directory: " + s);
which is supposed to work like new File(file).getParentFile().mkdirs()
. It might be wrong, but then it shouldn't run in the simulator either, so I'd call it a bug.
I get the message
Cannot create directory:
file:///data/user/0/my.package.name/files//dump/000/abcd
but the parent directory ("000") has been successfully created. Using adb shell
, I can create the directory using
mkdir /data/data/my.package.name/files/dump/000/abcd
so I can't see what's wrong. Any idea?
java io codenameone mkdirs
|
show 1 more comment
My code runs in the simulator, but crashes on Android with a FileNotFoundException
as it tries to FileSystemStorage#openOutputStream
in an non-existing directory. I create all the needed directories recursively before using
private void ensureParentDirs(String file)
final int j = file.lastIndexOf("/");
final String s = file.substring(0, j);
if (storage.isDirectory(s)) return;
storage.mkdir(s);
if (storage.isDirectory(s)) return;
ensureParentDirs(s);
storage.mkdir(s);
if (storage.isDirectory(s)) return;
Log.p("Cannot create directory: " + s);
which is supposed to work like new File(file).getParentFile().mkdirs()
. It might be wrong, but then it shouldn't run in the simulator either, so I'd call it a bug.
I get the message
Cannot create directory:
file:///data/user/0/my.package.name/files//dump/000/abcd
but the parent directory ("000") has been successfully created. Using adb shell
, I can create the directory using
mkdir /data/data/my.package.name/files/dump/000/abcd
so I can't see what's wrong. Any idea?
java io codenameone mkdirs
Why are you invokingmkdir()
and notmkdirs()
? Notice the method returns a boolean if the operation was successful. What did it return?
– Shai Almog
Nov 13 '18 at 4:14
@ShaiAlmog There's nomkdirs
in yourcom.codename1.io.FileSystemStorage
andmkdir
isvoid
. I guess, you meanFile
, but that's not what I'm using. I guess, I should, but that's the third thing (I started withStorage
).+++
I see, I can useFSS
withFile
easily.... however, what I'm doing doesn't look much different frommkdirs
.
– maaartinus
Nov 13 '18 at 4:56
Does it work when you don't have the double slash (... files//dump ...
)?
– Henry
Nov 13 '18 at 5:06
@Henry I didn't try... I know I should, but I've already spent too much time on this. I was thinking about it, but....files//dump
could be created, so double slashes in general should work. And in the meantime, I rewrote the code (for unrelated reasons....).
– maaartinus
Nov 13 '18 at 5:10
@ShaiAlmog It looks like there was a problem with doubles slashes as Henry assumed.
– maaartinus
Nov 13 '18 at 7:19
|
show 1 more comment
My code runs in the simulator, but crashes on Android with a FileNotFoundException
as it tries to FileSystemStorage#openOutputStream
in an non-existing directory. I create all the needed directories recursively before using
private void ensureParentDirs(String file)
final int j = file.lastIndexOf("/");
final String s = file.substring(0, j);
if (storage.isDirectory(s)) return;
storage.mkdir(s);
if (storage.isDirectory(s)) return;
ensureParentDirs(s);
storage.mkdir(s);
if (storage.isDirectory(s)) return;
Log.p("Cannot create directory: " + s);
which is supposed to work like new File(file).getParentFile().mkdirs()
. It might be wrong, but then it shouldn't run in the simulator either, so I'd call it a bug.
I get the message
Cannot create directory:
file:///data/user/0/my.package.name/files//dump/000/abcd
but the parent directory ("000") has been successfully created. Using adb shell
, I can create the directory using
mkdir /data/data/my.package.name/files/dump/000/abcd
so I can't see what's wrong. Any idea?
java io codenameone mkdirs
My code runs in the simulator, but crashes on Android with a FileNotFoundException
as it tries to FileSystemStorage#openOutputStream
in an non-existing directory. I create all the needed directories recursively before using
private void ensureParentDirs(String file)
final int j = file.lastIndexOf("/");
final String s = file.substring(0, j);
if (storage.isDirectory(s)) return;
storage.mkdir(s);
if (storage.isDirectory(s)) return;
ensureParentDirs(s);
storage.mkdir(s);
if (storage.isDirectory(s)) return;
Log.p("Cannot create directory: " + s);
which is supposed to work like new File(file).getParentFile().mkdirs()
. It might be wrong, but then it shouldn't run in the simulator either, so I'd call it a bug.
I get the message
Cannot create directory:
file:///data/user/0/my.package.name/files//dump/000/abcd
but the parent directory ("000") has been successfully created. Using adb shell
, I can create the directory using
mkdir /data/data/my.package.name/files/dump/000/abcd
so I can't see what's wrong. Any idea?
java io codenameone mkdirs
java io codenameone mkdirs
asked Nov 13 '18 at 3:42
maaartinusmaaartinus
27k2195231
27k2195231
Why are you invokingmkdir()
and notmkdirs()
? Notice the method returns a boolean if the operation was successful. What did it return?
– Shai Almog
Nov 13 '18 at 4:14
@ShaiAlmog There's nomkdirs
in yourcom.codename1.io.FileSystemStorage
andmkdir
isvoid
. I guess, you meanFile
, but that's not what I'm using. I guess, I should, but that's the third thing (I started withStorage
).+++
I see, I can useFSS
withFile
easily.... however, what I'm doing doesn't look much different frommkdirs
.
– maaartinus
Nov 13 '18 at 4:56
Does it work when you don't have the double slash (... files//dump ...
)?
– Henry
Nov 13 '18 at 5:06
@Henry I didn't try... I know I should, but I've already spent too much time on this. I was thinking about it, but....files//dump
could be created, so double slashes in general should work. And in the meantime, I rewrote the code (for unrelated reasons....).
– maaartinus
Nov 13 '18 at 5:10
@ShaiAlmog It looks like there was a problem with doubles slashes as Henry assumed.
– maaartinus
Nov 13 '18 at 7:19
|
show 1 more comment
Why are you invokingmkdir()
and notmkdirs()
? Notice the method returns a boolean if the operation was successful. What did it return?
– Shai Almog
Nov 13 '18 at 4:14
@ShaiAlmog There's nomkdirs
in yourcom.codename1.io.FileSystemStorage
andmkdir
isvoid
. I guess, you meanFile
, but that's not what I'm using. I guess, I should, but that's the third thing (I started withStorage
).+++
I see, I can useFSS
withFile
easily.... however, what I'm doing doesn't look much different frommkdirs
.
– maaartinus
Nov 13 '18 at 4:56
Does it work when you don't have the double slash (... files//dump ...
)?
– Henry
Nov 13 '18 at 5:06
@Henry I didn't try... I know I should, but I've already spent too much time on this. I was thinking about it, but....files//dump
could be created, so double slashes in general should work. And in the meantime, I rewrote the code (for unrelated reasons....).
– maaartinus
Nov 13 '18 at 5:10
@ShaiAlmog It looks like there was a problem with doubles slashes as Henry assumed.
– maaartinus
Nov 13 '18 at 7:19
Why are you invoking
mkdir()
and not mkdirs()
? Notice the method returns a boolean if the operation was successful. What did it return?– Shai Almog
Nov 13 '18 at 4:14
Why are you invoking
mkdir()
and not mkdirs()
? Notice the method returns a boolean if the operation was successful. What did it return?– Shai Almog
Nov 13 '18 at 4:14
@ShaiAlmog There's no
mkdirs
in your com.codename1.io.FileSystemStorage
and mkdir
is void
. I guess, you mean File
, but that's not what I'm using. I guess, I should, but that's the third thing (I started with Storage
). +++
I see, I can use FSS
with File
easily.... however, what I'm doing doesn't look much different from mkdirs
.– maaartinus
Nov 13 '18 at 4:56
@ShaiAlmog There's no
mkdirs
in your com.codename1.io.FileSystemStorage
and mkdir
is void
. I guess, you mean File
, but that's not what I'm using. I guess, I should, but that's the third thing (I started with Storage
). +++
I see, I can use FSS
with File
easily.... however, what I'm doing doesn't look much different from mkdirs
.– maaartinus
Nov 13 '18 at 4:56
Does it work when you don't have the double slash (
... files//dump ...
)?– Henry
Nov 13 '18 at 5:06
Does it work when you don't have the double slash (
... files//dump ...
)?– Henry
Nov 13 '18 at 5:06
@Henry I didn't try... I know I should, but I've already spent too much time on this. I was thinking about it, but
....files//dump
could be created, so double slashes in general should work. And in the meantime, I rewrote the code (for unrelated reasons....).– maaartinus
Nov 13 '18 at 5:10
@Henry I didn't try... I know I should, but I've already spent too much time on this. I was thinking about it, but
....files//dump
could be created, so double slashes in general should work. And in the meantime, I rewrote the code (for unrelated reasons....).– maaartinus
Nov 13 '18 at 5:10
@ShaiAlmog It looks like there was a problem with doubles slashes as Henry assumed.
– maaartinus
Nov 13 '18 at 7:19
@ShaiAlmog It looks like there was a problem with doubles slashes as Henry assumed.
– maaartinus
Nov 13 '18 at 7:19
|
show 1 more comment
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273462%2frecursive-directory-creation-fails-on-device%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273462%2frecursive-directory-creation-fails-on-device%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Why are you invoking
mkdir()
and notmkdirs()
? Notice the method returns a boolean if the operation was successful. What did it return?– Shai Almog
Nov 13 '18 at 4:14
@ShaiAlmog There's no
mkdirs
in yourcom.codename1.io.FileSystemStorage
andmkdir
isvoid
. I guess, you meanFile
, but that's not what I'm using. I guess, I should, but that's the third thing (I started withStorage
).+++
I see, I can useFSS
withFile
easily.... however, what I'm doing doesn't look much different frommkdirs
.– maaartinus
Nov 13 '18 at 4:56
Does it work when you don't have the double slash (
... files//dump ...
)?– Henry
Nov 13 '18 at 5:06
@Henry I didn't try... I know I should, but I've already spent too much time on this. I was thinking about it, but
....files//dump
could be created, so double slashes in general should work. And in the meantime, I rewrote the code (for unrelated reasons....).– maaartinus
Nov 13 '18 at 5:10
@ShaiAlmog It looks like there was a problem with doubles slashes as Henry assumed.
– maaartinus
Nov 13 '18 at 7:19