Click here to Skip to main content
12,403,812 members (75,647 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: Java Mobile 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
Updated 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 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 13 Feb 2013
Copyright © CodeProject, 1999-2016
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