私はたくさん探し回っていましたが、これを達成できませんでした。「Vector」を拡張したクラス「VectorEx」を作成し、2 つのメソッドを格納しました。1 つはベクトルを保存するためのもので、もう 1 つはベクトルをロードするためのものです。FileOutputStream と openFileInput() を使用する必要があることはわかっていますが、ファイルを作成できません。私はまだAndroidプログラミングにかなり慣れていないので、簡単な説明をいただければ幸いです。
public class VectorEx extends Vector<Subject> {
public void save(String name, Context ctx) {
try {
File file = new File(name);
if(!file.exists()) {
file.createNewFile();
}
FileOutputStream fos = ctx.openFileOutput(name, Context.MODE_PRIVATE);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(this);
oos.close();
}
catch(IOException e) {
e.printStackTrace();
}
}
public void load(String name, Context ctx) {
try {
FileInputStream fis = ctx.openFileInput(name);
ObjectInputStream ois = new ObjectInputStream(fis);
ois.readObject();
}
catch(IOException e) {
e.printStackTrace();
}
catch(ClassNotFoundException e) {
e.printStackTrace();
}
}
}
これは私が最後に試したコードです。私が LogCat について理解している限り、これは「読み取り専用ファイル システム」のようです。