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 <[email protected]> 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 [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
>



-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://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 [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