Create Properties from String - Java java.io

Java examples for java.io:Properties

Description

Create Properties from String

Demo Code


//package com.java2s;
import java.io.*;

import java.util.*;

public class Main {
    public static void main(String[] argv) {
        String props = "java2s.com";
        System.out.println(toProperties(props));
    }//from  ww w.  j a v  a 2s . c  o m

    @SuppressWarnings("deprecation")
    public static Properties toProperties(String props) {
        Properties p = new Properties();
        StringBufferInputStream sbi = new StringBufferInputStream(props);
        try {
            p.load(sbi);
        } catch (IOException e) {
            throw new RuntimeException(
                    "Unexpected Exception Converting String to Properties",
                    e);
        }
        return p;
    }
}

Related Tutorials