Java Properties Save serialize(Properties props)

Here you can find the source of serialize(Properties props)

Description

Serialize properties to a string suitable for a subsequent load()

License

GNU General Public License

Parameter

Parameter Description
props the properties

Exception

Parameter Description
IOException if an error occurs

Return

the string

Declaration

public static String serialize(Properties props) throws IOException 

Method Source Code


//package com.java2s;
/*// w ww .ja  v a  2  s.  c o  m
 * Copyright (C) 2002-2014 FlyMine
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  See the LICENSE file for more
 * information or http://www.gnu.org/copyleft/lesser.html.
 *
 */

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import java.util.Properties;

public class Main {
    /**
     * Serialize properties to a string suitable for a subsequent load()
     * @param props the properties
     * @return the string
     * @throws IOException if an error occurs
     */
    public static String serialize(Properties props) throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        props.store(baos, null);
        return baos.toString();
    }
}

Related

  1. saveSorted(Properties props, File file)
  2. saveSysDirProperties(Properties sysProps, String classpathDirectory)
  3. saveToFile(Properties prop, String fileName)
  4. saveUserSettings(Properties properties)
  5. serialize(Properties properties)