Can't write file to sdcard

Common bugs/problems with the Android SDK the Emulator and the ADT-Plugin.

Can't write file to sdcard

Postby Romeo Ordos » Wed Dec 02, 2009 6:15 pm

I try to write a file to sdcard using simple code:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. File file = new File("/sdcard/file.txt");
  2.                 try
  3.                 {
  4.                         file.createNewFile();
  5.                         Log.e("Info", "File Created!");
  6.                 }
  7.                 catch (IOException e)
  8.                 {
  9.                         Log.e("Error", e.toString());
  10.                 }
  11.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Operation successful in G1, but I have got java.io.IOException: Parent directory of file is not writable: /sdcard/file.txt in emulator

SDcard was created using wizard while creating virtual device in the latest AVD Manager(Linux). Virtual Device version is 1.6.
I have tried to change permissions of sdcard by "chmod 777 /sdcard" command in adb shell, but no effect.

DDMS shows: sdcard 1970-01-01 00:00 d---rwxr-x

Any idea?
Romeo Ordos
Junior Developer
Junior Developer
 
Posts: 11
Joined: Thu Aug 06, 2009 6:30 pm
Location: Donetsk, Ukraine

Top

Postby hardcoras » Wed Dec 02, 2009 11:46 pm

Maybe you forgot to add permissions to andriod manifest file.

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
hardcoras
Experienced Developer
Experienced Developer
 
Posts: 62
Joined: Sat Nov 14, 2009 2:31 pm
Location: Lithunia

Postby Romeo Ordos » Thu Dec 03, 2009 6:55 am

hardcoras wrote:Maybe you forgot to add permissions to andriod manifest file.

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />


Thanks. That's right. But I can't understand why real device writes files to SD without permissions!?
Romeo Ordos
Junior Developer
Junior Developer
 
Posts: 11
Joined: Thu Aug 06, 2009 6:30 pm
Location: Donetsk, Ukraine

Postby SCM » Thu Feb 25, 2010 1:31 am

i have the same problem, but the permission solution dindt worked :(
SCM
Junior Developer
Junior Developer
 
Posts: 16
Joined: Fri Feb 19, 2010 1:44 am

Postby robdev » Wed Mar 17, 2010 11:15 am

If you're running or debugging the program on a handset through Eclipse, don't forget to unmount or turn off USB storage to your SD card.

It doesn't allow both your computer and the Android system to access the SD Card at the same time.

Happy coding...
robdev
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Mar 17, 2010 11:03 am
Location: Australia

uses-permission must be outside of application tags

Postby lkleen » Fri Mar 26, 2010 10:20 pm

I could not write to my sdcard in the emulator nor on the device for quite a while, and I had the
<uses-permission android:name=android.permission.WRITE_EXTERNAL_STORAGE/>
line in the Manifest file.

I had assumed that it would need to be somewhere within the
<application ...
and
</application> tags

Finally, I moved it outside of those, next to the uses sdk tag, and now I can write to the sdcard.
Les
lkleen
Freshman
Freshman
 
Posts: 4
Joined: Wed Mar 17, 2010 8:43 pm
Location: United States

Top

Postby aro_ber » Mon Mar 29, 2010 3:29 pm

robdev wrote:If you're running or debugging the program on a handset through Eclipse, don't forget to unmount or turn off USB storage to your SD card.

It doesn't allow both your computer and the Android system to access the SD Card at the same time.

Happy coding...


I have the same problème! Please how can we unmount or turn off USB storage to my SD card ? I am using eclipse.
Thinks in advance !
The Internet is a minefield of opportunity. Step carefully, or another opportunity will go off right in your face
- Russell Davies
aro_ber
Freshman
Freshman
 
Posts: 2
Joined: Fri Mar 12, 2010 4:14 pm

Postby jitu_goldie » Mon Apr 26, 2010 1:38 pm

have u add the write permissions in ur manifest file..

checkout
KEEP TRYING..
jitu_goldie
Junior Developer
Junior Developer
 
Posts: 15
Joined: Thu Apr 08, 2010 7:52 am
Location: New Delhi

Re: Can't write file to sdcard

Postby fairygodmother » Wed May 26, 2010 8:34 am

Check the name of the file that you're trying to write to. I was getting the same error, and my permissions were correct, but it turns out android didn't like the fact that I had ":" and "+" in the filename. There may be other symbols that it dislikes as well.
fairygodmother
Once Poster
Once Poster
 
Posts: 1
Joined: Wed May 26, 2010 8:31 am

Re: Can't write file to sdcard

Postby herzoni » Tue Oct 05, 2010 9:49 pm

I did all the things above, but still it did not worked ... :(
somebody help please......
herzoni
Once Poster
Once Poster
 
Posts: 1
Joined: Tue Oct 05, 2010 9:45 pm

Top

Return to SDK/ADT/Emulator Problems

Who is online

Users browsing this forum: No registered users and 2 guests