您可以使用 Android SharedPreferences类来执行此操作,这是在启动之间保存设置的一种方式。
SharedPreferences appSettings = this.getSharedPreferences("fileName", 0);
SharedPreferences.Editor = appSettings.edit;
appSettings_Edit.putString("saveme", "this will be saved"); //First Parameter, name of the value, second parameter, value of the name
appSettings_Edit.commit(); //This is called to commit the changes to memory.
//This can be called anytime after `commit()`, including in any sequential launches, and it will return the vale of whatever you set.
appSettings.getString("saveme");
如果要保存实际file
文件,可以使用 BufferedWriter 在系统上创建一些硬文件:
BufferedWriter out = new BufferedWriter(new FileWriter(new File(fileName)));
out.write("I am a line of text written in" + fileName);
out.close();
然后,您可以使用 BufferedReader 检索文件的内容:
List<String> SomeStringListArray = new ArrayList<String>();
BufferedReader in = new BufferedReader(new FileReader(new File(fileName)));
String s;
while ((s = in.readLine()) != null) {
SomeStringListArray.add(s);
}
in.close();
您还可以在 Android 缓存目录中创建此文件,以便只有您的文件可以访问它,文件名的路径来自:
this.getChachDir();
this.getExternalCacheDir();