views:

421

answers:

2

There does not seem to be any Android manifest permission that needs to be set for file io.

public class Device extends Activity {
    private static final Configuration config = new Configuration();
    ...
    private boolean applyMenuChoice(MenuItem item) {
        switch (item.getItemId()) {
        ...
        case R.id.menuSave:
            ...
            configuration.modify(name, to, from, user);
            configuration.write();
            ...

public class Configuration extends Activity {
    private final static String CONFIG = "config.txt";
    private static StringBuilder config = new StringBuilder();
    ...
    public void write() {
        try {
            FileOutputStream fos = openFileOutput(CONFIG, Context.MODE_PRIVATE);
            fos.write(config.toString().getBytes());
            ...
+1  A: 

Where are you trying to write your file to? If it's on the SD-card of the device, you need to set the WRITE_EXTERNAL_STORAGE-permission in your android-manifest. You may also need to set a path instead of just using a filename.

Select0r
It is a small file. I am not trying to write to external storage, and I am fairly certain that openFileOutput does not accept file paths.
JackN
I added WRITE_EXTERNAL_STORAGE permission to the manifest to see if it would help, but it didn't, and I don't understand why this answer is marked as useful if it is not (at least not in this case).
JackN
A: 

Replacing the illegal instantiation of an activity with correct methods resolved this issue. Thank you very much (again) Falmarri.

JackN

related questions