Click here to Skip to main content
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 10-Feb-13 0:03am
Edited 10-Feb-13 8: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 OriginalGriff 8,284
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,614
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 13 Feb 2013
Copyright © CodeProject, 1999-2014
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