Can anyone tell me why my code below does not work? I’m trying to append a string to the contents of a text/html file. I just followed the code in the android dev docs here
package com.example.GetContentThenAppend;
import java.io.FileOutputStream;
import java.io.IOException;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Environment;
public class GetContentThenAppend extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
String FILENAME = Environment.getExternalStorageDirectory() + "/EngagiaDroid/videos.html";
String string = "<div style='color: blue; border: thin solid red;'>YO!</div>";
FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_APPEND);
fos.write(string.getBytes());
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
I guess your problem in permissions,, have you added write to files permission in your manifest. You can do this by adding this to the manifest file