これは、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();