Java Properties Save saveParamToFile(String fileName, String param, String value)

Here you can find the source of saveParamToFile(String fileName, String param, String value)

Description

save Param To File

License

Open Source License

Declaration


static public String saveParamToFile(String fileName, String param,
        String value) throws FileNotFoundException, IOException 

Method Source Code

//package com.java2s;
/*//from  ww  w . j  av  a 2 s. c o m
 * ISABEL: A group collaboration tool for the Internet
 * Copyright (C) 2009 Agora System S.A.
 * 
 * This file is part of Isabel.
 * 
 * Isabel is free software: you can redistribute it and/or modify
 * it under the terms of the Affero GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Isabel 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
 * Affero GNU General Public License for more details.
 * 
 * You should have received a copy of the Affero GNU General Public License
 * along with Isabel.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.io.*;

import java.util.*;

public class Main {

    static public String saveParamToFile(String fileName, String param,
            String value) throws FileNotFoundException, IOException {

        return saveParamToFile(fileName, param, value, new File(fileName)
                .getName().toString() + " PARAMS");

    }

    static public String saveParamToFile(String fileName, String param,
            String value, String fileTitle) throws FileNotFoundException,
            IOException {

        // cargamos las properties con los antiguos valores

        Properties p = new Properties();

        File file = new File(fileName);

        if (file.exists()) {

            p.load(new FileInputStream(fileName));

        }

        Object object = p.setProperty(param, value);

        String oldValue = "";

        if (object != null)
            oldValue = object.toString();

        p.store(new FileOutputStream(fileName), fileTitle);

        return oldValue;

    }
}

Related

  1. saveInstalledChecksumCache(File dir, Map checksums)
  2. saveMailAtt(String host, String userName, String password, String from, String directory)
  3. saveOccurrencesAsText(String fileName, TreeMap distribution, int frequency, char[] ignore)
  4. saveOutputFile(String prefix, String suffix, String data)
  5. saveParamsToFile(String fileName, String[] params)
  6. saveProperties()
  7. saveProperties(final IResource modelResource, final Properties props)
  8. saveProperties(Map map, File file, String encoding)
  9. saveProperties(Map map, Writer tmpWriter)