Example usage for java.util Properties get

List of usage examples for java.util Properties get

Introduction

In this page you can find the example usage for java.util Properties get.

Prototype

@Override
    public Object get(Object key) 

Source Link

Usage

From source file:Main.java

  public static void main(String args[]) throws Exception {
  Properties props = new Properties();
  URL url = ClassLoader.getSystemResource("props.properties");
  props.load(url.openStream());//w ww.  j a  va2s.c o m
  System.out.println("prop1 :\n " + props.get("prop1"));
  System.out.println("prop2 :\n " + props.get("prop2"));
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    Properties props = new Properties();
    URL url = ClassLoader.getSystemResource("props.properties");
    props.load(url.openStream());/*from   www  .  j a v  a 2 s .  c  o  m*/
    System.out.println("prop1 :\n " + props.get("prop1"));
    System.out.println("prop2 :\n " + props.get("prop2"));
}

From source file:Main.java

public static void main(String[] args) {
    ResourceBundle resource = ResourceBundle.getBundle("Messages", Locale.UK);

    Properties properties = convertResourceBundleToProperties(resource);

    Enumeration keys = properties.keys();
    while (keys.hasMoreElements()) {
        String key = (String) keys.nextElement();
        String value = (String) properties.get(key);
        System.out.println(key + " = " + value);
    }//www. j  a  v  a 2 s. c  o  m
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Properties props = System.getProperties();

    Enumeration e = props.propertyNames();
    for (; e.hasMoreElements();) {
        String propName = (String) e.nextElement();
        System.out.println(propName);
        String propValue = (String) props.get(propName);
        System.out.println(propValue);
    }/*ww w  . ja v a2s . c o  m*/
}

From source file:Main.java

public static void main(String[] args) throws IOException {
    Properties properties = new Properties();
    try (InputStream input = new FileInputStream("test.properties")) {
        properties.load(input);//from  www.j  a va 2s . c  o  m
    }

    for (String key : properties.stringPropertyNames()) {
        System.out.println(key + " = '" + properties.get(key) + "'");
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Properties config = new Properties();
    config.load(new FileInputStream("conf-file.pros"));

    Enumeration en = config.keys();
    while (en.hasMoreElements()) {
        String key = (String) en.nextElement();
        System.out.println(key + ":" + config.get(key));
    }//  ww w.j  ava  2 s .c  o  m
}

From source file:com.camel.trainreserve.TicketReserver.java

public static void main(String[] args) {
    getCaptchaImg();/*w  w w  .  ja  va 2s .  co m*/

    String filePath = FileUtils.getFileAbsolutePath();
    Properties props = FileUtils.readProperties(filePath + "/trainreserve/checkorderInfo.properties");
    Iterator it = props.keySet().iterator();
    while (it.hasNext()) {
        String key = (String) it.next();
        NameValuePair nvp = new BasicNameValuePair(key, (String) props.get(key));
        datas.add(nvp);
    }
    String formDate = URLEncodedUtils.format(datas, "UTF-8");
    String res = null;
    try {
        res = JDKHttpsClient.doPost(checkOrderUrl, cookieStr, formDate, "UTF-8", 3000, 2000);
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.out.println("response =" + res);
}

From source file:net.roboconf.iaas.openstack.IaasOpenstack.java

public static void main(String args[]) throws Exception {

    Map<String, String> conf = new HashMap<String, String>();

    java.util.Properties p = new java.util.Properties();
    p.load(new java.io.FileReader(args[0]));

    for (Object name : p.keySet()) {
        conf.put(name.toString(), p.get(name).toString());
    }/*w  ww  . ja v  a  2 s. co m*/
    // conf.put("openstack.computeUrl", "http://localhost:8888/v2");

    IaasOpenstack iaas = new IaasOpenstack();
    iaas.setIaasProperties(conf);

    String machineImageId = conf.get("openstack.image");
    String channelName = "test";
    String applicationName = "roboconf";
    String ipMessagingServer = "localhost";
    String serverId = iaas.createVM(machineImageId, ipMessagingServer, channelName, applicationName);
    /*Thread.sleep(25000);
    iaas.terminateVM(serverId);*/
}

From source file:com.cyclopsgroup.waterview.jelly.JellyRunner.java

/**
 * Main entry to run a script/*from   w  ww . j  a  v a 2  s  .c  o  m*/
 * 
 * @param args Script paths
 * @throws Exception Throw it out
 */
public static final void main(String[] args) throws Exception {
    List scripts = new ArrayList();
    for (int i = 0; i < args.length; i++) {
        String path = args[i];
        File file = new File(path);
        if (file.isFile()) {
            scripts.add(file.toURL());
        } else {
            Enumeration enu = JellyRunner.class.getClassLoader().getResources(path);
            CollectionUtils.addAll(scripts, enu);
        }
    }
    if (scripts.isEmpty()) {
        System.out.println("No script to run, return!");
        return;
    }

    String basedir = new File("").getAbsolutePath();
    Properties initProperties = new Properties(System.getProperties());
    initProperties.setProperty("basedir", basedir);
    initProperties.setProperty("plexus.home", basedir);

    WaterviewPlexusContainer container = new WaterviewPlexusContainer();
    for (Iterator j = initProperties.keySet().iterator(); j.hasNext();) {
        String initPropertyName = (String) j.next();
        container.addContextValue(initPropertyName, initProperties.get(initPropertyName));
    }

    container.addContextValue(Waterview.INIT_PROPERTIES, initProperties);
    container.initialize();
    container.start();

    JellyEngine je = (JellyEngine) container.lookup(JellyEngine.ROLE);
    JellyContext jc = new JellyContext(je.getGlobalContext());

    for (Iterator i = scripts.iterator(); i.hasNext();) {
        URL script = (URL) i.next();
        System.out.print("Running script " + script);
        jc.runScript(script, XMLOutput.createDummyXMLOutput());
        System.out.println("... Done!");
    }
    container.dispose();
}

From source file:LauncherBootstrap.java

/**
 * The main method./* w  w  w  .  java  2  s  .c  o m*/
 *
 * @param args command line arguments
 */
public static void main(String[] args) {

    try {

        // Try to find the LAUNCHER_JAR_FILE_NAME file in the class
        // loader's and JVM's classpath.
        URL coreURL = LauncherBootstrap.class.getResource("/" + LauncherBootstrap.LAUNCHER_JAR_FILE_NAME);
        if (coreURL == null)
            throw new FileNotFoundException(LauncherBootstrap.LAUNCHER_JAR_FILE_NAME);

        // Coerce the coreURL's directory into a file
        File coreDir = new File(URLDecoder.decode(coreURL.getFile())).getCanonicalFile().getParentFile();

        // Try to find the LAUNCHER_PROPS_FILE_NAME file in the same
        // directory as this class
        File propsFile = new File(coreDir, LauncherBootstrap.LAUNCHER_PROPS_FILE_NAME);
        if (!propsFile.canRead())
            throw new FileNotFoundException(propsFile.getPath());

        // Load the properties in the LAUNCHER_PROPS_FILE_NAME 
        Properties props = new Properties();
        FileInputStream fis = new FileInputStream(propsFile);
        props.load(fis);
        fis.close();

        // Create a class loader that contains the Launcher, Ant, and
        // JAXP classes.
        URL[] antURLs = LauncherBootstrap
                .fileListToURLs((String) props.get(LauncherBootstrap.ANT_CLASSPATH_PROP_NAME));
        URL[] urls = new URL[1 + antURLs.length];
        urls[0] = coreURL;
        for (int i = 0; i < antURLs.length; i++)
            urls[i + 1] = antURLs[i];
        ClassLoader parentLoader = Thread.currentThread().getContextClassLoader();
        URLClassLoader loader = null;
        if (parentLoader != null)
            loader = new URLClassLoader(urls, parentLoader);
        else
            loader = new URLClassLoader(urls);

        // Load the LAUNCHER_MAIN_CLASS_NAME class
        launcherClass = loader.loadClass(LAUNCHER_MAIN_CLASS_NAME);

        // Get the LAUNCHER_MAIN_CLASS_NAME class' getLocalizedString()
        // method as we need it for printing the usage statement
        Method getLocalizedStringMethod = launcherClass.getDeclaredMethod("getLocalizedString",
                new Class[] { String.class });

        // Invoke the LAUNCHER_MAIN_CLASS_NAME class' start() method.
        // If the ant.class.path property is not set correctly in the 
        // LAUNCHER_PROPS_FILE_NAME, this will throw an exception.
        Method startMethod = launcherClass.getDeclaredMethod("start", new Class[] { String[].class });
        int returnValue = ((Integer) startMethod.invoke(null, new Object[] { args })).intValue();
        // Always exit cleanly after invoking the start() method
        System.exit(returnValue);

    } catch (Throwable t) {

        t.printStackTrace();
        System.exit(1);

    }

}