openFileOutput() 的用途是什么?
For what is openFileOutput() used for?
我有这段代码。
有人可以帮助 openFileOutput 中的“0”属性在以下代码中代表什么吗?
public void Save(String fileName) {
try {
OutputStreamWriter out =
new OutputStreamWriter(openFileOutput(fileName, 0));
out.write(EditText1.);
out.close();
Toast.makeText(this, "Note Saved!", Toast.LENGTH_SHORT).show();
} catch (Throwable t) {
Toast.makeText(this, "Exception: " + t.toString(), Toast.LENGTH_LONG).show();
}
}
int: Operating mode.
Value is either 0 or combination of MODE_PRIVATE, MODE_WORLD_READABLE, MODE_WORLD_WRITEABLE or MODE_APPEND.
https://developer.android.com/reference/android/content/Context.html
建议使用常量,但 0 是 Context.MODE_PRIVATE
来自 Context.openFileOutput
, the 0 represents the mode for opening the file. In this case, 0 is a synonym for MODE_PRIVATE
的文档:
File creation mode: the default mode, where the created file can only be accessed by the calling application (or all applications sharing the same user ID).
因此只有创建该文件的应用程序才能在以后访问它。另一个选项是 MODE_APPEND
,它在当前端点打开文件并向其添加额外数据。
我有这段代码。
有人可以帮助 openFileOutput 中的“0”属性在以下代码中代表什么吗?
public void Save(String fileName) {
try {
OutputStreamWriter out =
new OutputStreamWriter(openFileOutput(fileName, 0));
out.write(EditText1.);
out.close();
Toast.makeText(this, "Note Saved!", Toast.LENGTH_SHORT).show();
} catch (Throwable t) {
Toast.makeText(this, "Exception: " + t.toString(), Toast.LENGTH_LONG).show();
}
}
int: Operating mode.
Value is either 0 or combination of MODE_PRIVATE, MODE_WORLD_READABLE, MODE_WORLD_WRITEABLE or MODE_APPEND.
https://developer.android.com/reference/android/content/Context.html
建议使用常量,但 0 是 Context.MODE_PRIVATE
来自 Context.openFileOutput
, the 0 represents the mode for opening the file. In this case, 0 is a synonym for MODE_PRIVATE
的文档:
File creation mode: the default mode, where the created file can only be accessed by the calling application (or all applications sharing the same user ID).
因此只有创建该文件的应用程序才能在以后访问它。另一个选项是 MODE_APPEND
,它在当前端点打开文件并向其添加额外数据。