Java Properties Save saveParamsToFile(String fileName, String[] params)

Here you can find the source of saveParamsToFile(String fileName, String[] params)

Description

guarda las tuplas parametro-valor en el fichero dado.

License

Open Source License

Parameter

Parameter Description
fileName fichero donde se almacenan las tuplas parametro-valor
params tuplas parametro-valor a guardar

Exception

Parameter Description
FileNotFoundException , IOException si hubo algun problema.

Declaration


static public void saveParamsToFile(String fileName, String[] params)
        throws FileNotFoundException, IOException 

Method Source Code

//package com.java2s;
/*/*from  ww w . j  a v a2s . c om*/
 * 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 {
    /**

     * guarda las tuplas parametro-valor en el fichero dado. Antes de guardarlas, elimina el contenido del fichero, si existia.

     * @param fileName fichero donde se almacenan las tuplas parametro-valor

     * @param params tuplas parametro-valor a guardar

     * @throws FileNotFoundException, IOException si hubo algun problema.

     * @Author lailoken

     */

    static public void saveParamsToFile(String fileName, String[] params)
            throws FileNotFoundException, IOException {

        saveParamsToFile(fileName, params, new File(fileName).getName()
                .toString() + " PARAMS");

    }

    /**

     * guarda las tuplas parametro-valor en el fichero dado

     * @param fileName fichero donde se almacenan las tuplas parametro-valor

     * @param params tuplas parametro-valor a guardar

     * @param fileTitle comentario q es escribe al comienzo del fichero

     * @throws FileNotFoundException, IOException si hubo algun problema.

     * @Author lailoken

     */

    static public void saveParamsToFile(String fileName, String[] params,
            String fileTitle) throws FileNotFoundException, IOException {

        Properties p = new Properties();

        File file = new File(fileName);

        if (file.exists()) {

            p.load(new FileInputStream(fileName));

        }

        for (int i = 0; i < params.length; i = i + 2) {

            //System.out.println("param: " + params[i] + ", value: " + params[i+1]);

            p.setProperty(params[i], params[i + 1]);

        }

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

    }
}

Related

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