Android的:如何存储在内存中的数据? [英] Android: How to store data on internal memory?
本文介绍了Android的:如何存储在内存中的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是完全描述这里如何做到这一点,唯一的问题:他不知道该功能的 openFileOutput()
;
私人无效saveSettingsFile(){
字符串文件名=设置;
串串=世界,你好!;
FileOutputStream中FOS = openFileOutput(文件名,Context.MODE_PRIVATE); // openFileOutput红色下划线
尝试 {
fos.write(string.getBytes());
fos.close();
}赶上(IOException异常E){
Log.e(控制器,e.getMessage()+ e.getLocalizedMessage()+ e.getCause());
}
}
这些都是我进口相关的包:
进口java.io.FileOutputStream中;
进口java.io.IOException异常;
进口android.content.Context;
解决方案
看一看<一href="http://developer.android.com/resources/samples/Backu$p$pstore/src/com/example/android/backu$p$pstore/ExampleAgent.html"相对=nofollow>这个例子使用FileOutputStrem从dev.android.com的实例。它应该给你如何正确使用它的想法。
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;
解决方案
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.
这篇关于Android的:如何存储在内存中的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文