Java Properties Load loadProperties(String properties)

Here you can find the source of loadProperties(String properties)

Description

Loads a key/value pair string as Properties

License

Open Source License

Declaration

public static Properties loadProperties(String properties) throws IOException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 *
 * Copyright (c) 2004-2011 Oracle Corporation.
 *
 * 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 ww  . j a v a  2s.  c  om
 *
 *    Kohsuke Kawaguchi, Winston Prakash
 *     
 *
 *******************************************************************************/

import java.io.ByteArrayInputStream;

import java.io.IOException;

import java.io.StringReader;

import java.util.Properties;

public class Main {
    /**
     * Loads a key/value pair string as {@link Properties}
     * @since 1.392
     */
    public static Properties loadProperties(String properties) throws IOException {
        Properties p = new Properties();
        try {
            p.load(new StringReader(properties));
        } catch (NoSuchMethodError e) {
            // load(Reader) method is only available on JDK6.
            // this fall back version doesn't work correctly with non-ASCII characters,
            // but there's no other easy ways out it seems.
            p.load(new ByteArrayInputStream(properties.getBytes()));
        }
        return p;
    }
}

Related

  1. loadProperties(Properties properties, Class baseClass, String... propertiesName)
  2. loadProperties(Properties props, final Class clazz, final String resourceName)
  3. loadProperties(String bucketName, String key)
  4. loadProperties(String conf)
  5. loadProperties(String name, ClassLoader loader)
  6. loadProperties(String properties)
  7. loadProperties(String propertyName)
  8. loadProperties(String resource)
  9. loadProperties(String resourceName)