Sunday, June 12, 2011

[android-developers] Re: Can't write to sdcard

Still getting the same error. I followed your advice with:

File sdDir = Environment.getExternalStorageDirectory();
sdDir.mkdirs();
File file = new File(sdDir +currentTripName+".kml");
FileWriter sdWriter = new FileWriter(file, false);
sdWriter.write(fileContents);
sdWriter.close();

also, the manifest includes:
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
which i have placed outside of the application tags.

On Jun 12, 11:09 am, Mark Murphy <mmur...@commonsware.com> wrote:
> Never never never hardwire paths. For example, your paths are wrong
> for modern versions of Android. Use
> Environment.getExternalStorageDirectory() for the root of external
> storage.
>
> Also, make sure you have the WRITE_EXTERNAL_STORAGE permission.
>
>
>
>
>
> On Sun, Jun 12, 2011 at 10:31 AM, Ab Caballero <a...@mac.com> wrote:
> > I am attempting to save data to the sdcard with the following code but
> > get a file not found exception:
>
> > String fileContents = fileBuf.toString();
> > Log.d(tag, fileContents);
> > File sdDir = new File("/sdcard/Logger");
> > sdDir.mkdirs();
> > File file = new File("/sdcard/Logger/"+currentTripName+".kml");
> > FileWriter sdWriter = new FileWriter(file, false);
> > sdWriter.write(fileContents);
> > sdWriter.close();
>
> > When i try the following code (API level 8), I get a similar error.
>
> > File sdDir = getExternalFilesDir(null);
> > File file = new File(getExternalFilesDir(null) + currentTripName
> > +".kml");
> > FileWriter sdWriter = new FileWriter(file, false);
> > sdWriter.write(fileContents);
> > sdWriter.close();
>
> > Any suggestions? This is driving me nuts.
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to android-developers@googlegroups.com
> > To unsubscribe from this group, send email to
> > android-developers+unsubscribe@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en
>
> --
> Mark Murphy (a Commons Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy
>
> Android Training in NYC:http://marakana.com/training/android/

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate