Click here to Skip to main content
11,702,130 members (62,328 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java Android
Code:
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:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
But get exception:
java.io.FileNotFoundException: /mnt/sdcard/mobile_recont/settings: open failed: EACCES (Permission denied)
and
Environment.getExternalStorageState() = "removed" 
Why? - SD card is correctly setted in emulator.
Please help.
Posted 9-Feb-13 23:03pm
halabella1.3K
Edited 10-Feb-13 7:22am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try creating the folders before saving files in them : http://stackoverflow.com/questions/4776426/how-to-create-a-directory-in-android[^]
  Permalink  
Comments
halabella at 11-Feb-13 8:16am
   
It's helpless.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

SD cards have a "write lock" slider on the side, 90 degrees from the contacts.

Make sure that your SD card is write enabled.
  Permalink  

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

  Print Answers RSS
0 Maciej Los 395
1 Sergey Alexandrovich Kryukov 355
2 OriginalGriff 314
3 CHill60 145
4 Mika Wendelius 119
0 OriginalGriff 8,344
1 Sergey Alexandrovich Kryukov 7,507
2 CPallini 4,922
3 Maciej Los 4,371
4 Mika Wendelius 3,556


Advertise | Privacy | Mobile
Web02 | 2.8.150819.1 | Last Updated 13 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100