我在加载保存文件时遇到麻烦,它在2个int变量的.readObject()中显示“找不到符号”错误。我正确地声明了变量,并且两个变量都是全局的。我不知道为什么。我试图寻找答案,所以我最终在这里。提前ty家伙

public void loadGame()
{
    //Load Game
    try
    {
        FileOutputStream saveFile = new FileOutputStream("save.txt");
        ObjectOutputStream load = new ObjectOutputStream(saveFile);
        cursortrigger = (Integer) load.readObject();
        soundtrigger = (Integer) load.readObject();
        load.close();
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }

}
public void saveGame()
{
    //Save Game
    try
    {
        FileOutputStream saveFile = new FileOutputStream("save.txt");
        ObjectOutputStream save = new ObjectOutputStream(saveFile);
        save.writeObject(cursortrigger);
        save.writeObject(soundtrigger);
        save.close();
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }

}

最佳答案

FileOutputStream saveFile = new FileOutputStream("save.txt");
ObjectOutputStream load = new ObjectOutputStream(saveFile);


错了要读取对象,您需要ObjectInputStreamFileInputStream

FileInputStream saveFile = new FileInputStream("save.txt");
ObjectInputStream load = new ObjectInputStream(saveFile);

关于java - 在.readObject()上找不到符号;,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24822399/

10-08 21:53