Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Code:
Java
String FILENAME = "settings";
String string = "hello world!";
File sdDir = new File(Environment.getExternalStorageDirectory().getPath());
File testDir = new File(sdDir.getAbsolutePath() + "/mobile_recont");
testDir.mkdir();

FILENAME = testDir + "/"+ FILENAME;
try {
    FileOutputStream fos = new FileOutputStream(FILENAME);
    fos.write(string.getBytes());
    fos.flush();
    fos.close();
    } catch (IOException e) {
Log.e("Controller", e.getMessage() + e.getLocalizedMessage() + e.getCause());
                    }


I also wrote in manifest:
XML
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

But get exception:
XML
java.io.FileNotFoundException: /mnt/sdcard/mobile_recont/settings: open failed: EACCES (Permission denied)

and
Java
Environment.getExternalStorageState() = "removed" 

Why? - SD card is correctly setted in emulator.
Please help.
Posted
Updated 10-Feb-13 7:22am
v2

Try creating the folders before saving files in them : http://stackoverflow.com/questions/4776426/how-to-create-a-directory-in-android[^]
 
Share this answer
 
Comments
[no name] 11-Feb-13 8:16am    
It's helpless.
SD cards have a "write lock" slider on the side, 90 degrees from the contacts.

Make sure that your SD card is write enabled.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900