Here you can find the source of saveEasyQuestImpl(final String quest, final File targetFile)
private static void saveEasyQuestImpl(final String quest, final File targetFile)
//package com.java2s; /*/* w ww .j a v a 2s. c om*/ * This file is part of the Illarion easyQuest Editor. * * Copyright 2011 - Illarion e.V. * * The Illarion easyQuest Editor is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or (at your * option) any later version. * * The Illarion easyQuest Editor is distributed in the hope that it will be * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * Public License for more details. * * You should have received a copy of the GNU General Public License along with * the Illarion easyQuest Editor. If not, see <http://www.gnu.org/licenses/>. */ import java.io.File; import java.io.FileWriter; import java.io.IOException; public class Main { private static void saveEasyQuestImpl(final String quest, final File targetFile) { final File backupFile = new File(targetFile.getAbsolutePath() + ".bak"); //$NON-NLS-1$ FileWriter fw = null; try { if (backupFile.exists()) { backupFile.delete(); } if (targetFile.exists()) { targetFile.renameTo(backupFile); } fw = new FileWriter(targetFile); fw.write(quest); if (backupFile.exists()) { backupFile.delete(); } } catch (final Exception e) { if (backupFile.exists()) { if (targetFile.exists()) { targetFile.delete(); } backupFile.renameTo(targetFile); } //LOGGER.error("Writing the easyNPC Script failed.", e); //$NON-NLS-1$ } finally { if (fw != null) try { fw.close(); } catch (IOException e) { } } } }