Java Properties to toStringProperties(String name, Properties props)

Here you can find the source of toStringProperties(String name, Properties props)

Description

get String representing the given properties.

License

Open Source License

Parameter

Parameter Description
name name of properties
props properties whose keys and values will be printed out.

Declaration

public static String toStringProperties(String name, Properties props) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2007, 2010 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*  w  w w. jav a  2s  .c  om*/
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

import java.util.*;

public class Main {
    /**
     * get String representing the given properties.
     * 
     * @param name name of properties 
     * @param props properties whose keys and values will be printed out.
     */
    public static String toStringProperties(String name, Properties props) {
        if (props == null || props.size() == 0) {
            return "Props(" + name + ") is empty\n";
        }
        StringBuffer sb = new StringBuffer();
        sb.append("Props(" + name + ") is \n");
        for (Enumeration enumeration = props.keys(); enumeration.hasMoreElements();) {
            String key = (String) enumeration.nextElement();
            sb.append("\tkey=" + key + "\tvalue=" + props.getProperty(key) + "\n");
        }
        return sb.toString();
    }
}

Related

  1. PropertiesToInputStream(Properties p)
  2. propertiesToXmlByteArray(Properties p)
  3. toString(Properties props)