Here's what I'm doing:
static void writeToFile(String text) {
try {
synchronized (fileLock) {
File external = Environment.getExternalStorageDirectory();
String sdcardPath = external.getPath();
FileWriter filewriter = new FileWriter(sdcardPath
+ "/Documents/myfile.txt", true);
BufferedWriter out = new BufferedWriter(filewriter);
out.write(text);
out.close();
filewriter.close();
}
} catch (Exception e) {
android.util.Log.d("failed to save file", e.toString());
}
}
On open file I get following exception:
java.io.FileNotFoundException: /mnt/sdcard/Documents/myfile.txt:
open failed: ENOENT (No such file or directory)
- The directory
/mnt/sdcard/Documents/
exists according to Root Browres - The application manifest does contain
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
myfile.txt
does not exist, I want it created or appended
How do I create or append to a file on android?
UPDATE Here is my AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mytest"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>