Java 将HashMap写入文本文件Android studio

Java 将HashMap写入文本文件Android studio,java,android,hashmap,Java,Android,Hashmap,我曾尝试使用序列化将HashMap写入文本文件,但它似乎不起作用。我不确定我是否用错了 我的Hashmap: HashMap lettsavailable=新HashMap(); 还有我用来序列化的代码 public void onResume(){ super.onResume(); try { FileInputStream fileInputStream = new FileInputStream(getApplica

我曾尝试使用序列化将HashMap写入文本文件,但它似乎不起作用。我不确定我是否用错了 我的Hashmap: HashMap lettsavailable=新HashMap(); 还有我用来序列化的代码

public void onResume(){
        super.onResume();
        try
        {
            FileInputStream fileInputStream = new FileInputStream(getApplicationContext().getFilesDir()+"/FenceInformation.ser");
            ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
            Map lettersAvailable = (Map)objectInputStream.readObject();
            Toast.makeText(this,"Hashmap reloaded",Toast.LENGTH_SHORT);
        }
        catch(ClassNotFoundException | IOException | ClassCastException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onPause(){
        super.onPause();

        try
        {
            FileOutputStream fos = getApplicationContext().openFileOutput("YourInfomration.ser", Context.MODE_PRIVATE);
            ObjectOutputStream oos = new ObjectOutputStream(fos);
            oos.writeObject(lettersAvailable);
            oos.close();
            Log.d(TAG, "onCreate() Restoring previous state");
        } catch (IOException e) {
            e.printStackTrace();
        }


   }
在onResume方法中,它表示lettersAvailable变量从未在映射lettersAvailable中使用


没有其他方法可以这样做吗?

您介意给出显示的错误吗?它不会给我错误。只是没有把文件归档,否则我就找错地方了。在onResume中,它告诉我我的lettersAvailable(我的hashMap)从未被使用过。