这是完全描述这里如何做到这一点,唯一的问题:他不知道该功能的 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;
解决方案
看一看这个例子使用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.