You're absolutely right, myFile.txt was a directory (who knew!?)  So
now I'm making one instance of File and calling mkdirs on just "/
sdcard/zackcorp/myfiles/", and then I'm making a second instance of
File, this time with that path AND the file name, and just calling
File.createNewFile(), it worked perfectly.

Thanks very much for your help!

-UBZack

On Oct 6, 4:13 pm, Jason Proctor <[EMAIL PROTECTED]> wrote:
> this is because file.mkdirs() doesn't understand that the second
> argument you provided to the File constructor is a file name rather
> than a directory name. i think you might find, and indeed i found,
> that /sdcard/zackcorp/myfiles/myFile.txt is actually a directory. the
> directory is writable in the sense that you can put files in it, but
> you can't directly open it for writing using a FOS.
>
> btw, i've so far found nothing weird in the Android File package.
> well, except that createTempFile() will return a file that's not
> writable if there is nothing mounted on /sdcard. that should be fixed
> IMHO.
>
> hope this helps,
> j
>
> >Hi All,
>
> >This is my code that successfully creates both the directory tree and
> >the file "myFile.txt", and yet throws a FileNotFoundException when I
> >try to call new FileOutputStream(file):
>
> >File file = new File("/sdcard/zackcorp/myfiles", "myFile.txt");
> >file.mkdirs();  // creates /sdcard/zackcorp/myfiles
> >file.createNewFile();
> >boolean canWrite = file.canWrite();  // canWrite is true
> >FileOutputStream fos = new FileOutputStream(file);
>
> >My theory is that it's not possible to create a FileOutputStream with
> >an sdcard file (or perhaps anywhere else besides within my package),
> >because when I change the directory to point to my package's sandbox,
> >the FileOutputStream is successfully made.
>
> >File file = new File("/data/data/com.zackcorp.android/myfiles",
> >"myFile.txt");
> >file.mkdirs();  // creates /data/data/com.zackcorp.android/myfiles
> >file.createNewFile();
> >boolean canWrite = file.canWrite();  // canWrite is true
> >FileOutputStream fos = new FileOutputStream(file); // THIS time it
> >works
>
> >Could anyone tell me what I have to do to open a FileOutputStream on a
> >file on an sdcard?  Or which AndroidManifest permission I could set to
> >fix this?  Thanks very much!
>
> >-UBZack
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to