Save data to file in android internal memory

Asked

Viewed 295 times

1

I need to record a set of variables:

int var1,var2,var3
var4=new int[10], var5=new int[10], var6=new int[10]
var7=new int[5][3],var8=new int[5][3]

My goal was to record them all in order and then read them all in the same order. By the other posts I saw, to record in internal memory I have to use the openFileOutput() but I couldn’t find any example that would explain to me how to pass array´s, arrays bidimensionais. Can someone tell me how to fix this?

  • An alternative would be to use a Webview, and use the function of writing data to the device on Html5. If you choose this form, this article may help you: http://www.devmedia.com.br/activities-basicas-ao-processo-development-software/5413

1 answer

2

Well, I’m not sure I understand what you need to do. But come on, from what I understand is that you need to save values in android memory, but need to be in a specific file? Otherwise, you can only use Sharedpreferences, which serves exactly to save small amounts of data, giving each one a key and adding its value. Example: https://developer.android.com/training/basics/data-storage/shared-preferences.html?hl=pt-br

But if your plan is really save to file:

String FILENAME = "hello_file";
String string = "hello world!";

FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
fos.write(string.getBytes());
fos.close();

In doubt, take a look here, about storage methods :

https://developer.android.com/guide/topics/data/data-storage.html

Browser other questions tagged

You are not signed in. Login or sign up in order to post.