Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to store data on internal memory?

It's perfectly described here how to do it, the only problem: He doesnt know the function openFileOutput();

private void saveSettingsFile() {
          String FILENAME = "settings";
          String string = "hello world!";

          FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE); //openFileOutput underlined red
          try {
            fos.write(string.getBytes());
            fos.close();
          } catch (IOException e) {
            Log.e("Controller", e.getMessage() + e.getLocalizedMessage() + e.getCause());
          }
}

Those are the relevant packages I imported:

import java.io.FileOutputStream;
import java.io.IOException;
import android.content.Context;
like image 732
OneWorld Avatar asked Sep 02 '10 14:09

OneWorld


People also ask

How can I use mobile internal storage?

All you have to do is open that app and select the "Show internal storage" option in its menu to browse through your phone's full internal storage. You can then open, move, rename, copy, delete, and share files as needed.

What is the best way to store data in Android?

You can use external storage if the data that your application stores can be used by other applications. Additionally, if the file stored by your application is huge, such as a video, you can save it to external storage. You can use external storage to keep the data even after uninstalling the application.


2 Answers

Have a look at this example of using a FileOutputStrem from the Examples on dev.android.com. It should give you an idea of how to use it correctly.

like image 73
fredley Avatar answered Oct 03 '22 08:10

fredley


Class within which this method is declared, is defined as "Static". thats why it is throwing error. Remove static from the class definition and bingo...

like image 39
Ted Avatar answered Oct 03 '22 08:10

Ted