I wrote this to store a file in SD card, but it's not working.
public class TestarFilesActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
File root = Environment.getExternalStorageDirectory();
try {
if (root.canWrite()) {
File file = new File(root, "agora.txt");
FileWriter fwriter = new FileWriter(file);
BufferedWriter out = new BufferedWriter(fwriter);
out.write("Hello world");
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}TestarFilesActivity.this.finish();
}
}
How is this problem caused and how can I solve it? I think it's everything right and I have write the permission in the manifest too.