Java FileWriter Write saveEasyQuestImpl(final String quest, final File targetFile)

Here you can find the source of saveEasyQuestImpl(final String quest, final File targetFile)

Description

save Easy Quest Impl

License

Open Source License

Declaration

private static void saveEasyQuestImpl(final String quest, final File targetFile) 

Method Source Code

//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) {
                }
        }
    }
}

Related

  1. saveData(String fileName, double totalTime, int[] resultSubset)
  2. saveDictionary(String fileName, Map values)
  3. saveDotGraph(final String dotGraph, final File outputDirectory)
  4. saveDoubleArray2File(Double[] doubleArray, String fileName)
  5. saveDoubleArray2FileAppend(Double[] doubleArray, String fileName)
  6. saveFile(File directory, String fileName, String content)
  7. saveFile(File file, String contents)
  8. saveFile(File file, String data)
  9. saveFile(File file, String fileContent)