Пример #1
0
  public void saveGameInformation(Game currentGame) {

    PrintWriter gameWriter;
    String saveFile = "save file.txt";

    try {
      // Creates the save file.
      gameWriter = new PrintWriter(saveFile);

      gameWriter.append(currentGame.getGameTitle() + "\n");
      gameWriter.append(currentGame.getFunRanking() + "\n");
      for (int count = 0; count < currentGame.getGameRules().size(); count++) {
        gameWriter.append(currentGame.getGameRules().get(count) + "\n");
      }
      gameWriter.append(" ;" + "\n");
      // Required to prevent corruption of data and maintain the security
      // of the file.
      gameWriter.close();
    } catch (FileNotFoundException noFileExists) {
      JOptionPane.showMessageDialog(appFrame, "Could not create the save file. :");
      JOptionPane.showMessageDialog(appFrame, noFileExists.getMessage());
    }
  }