Monday, May 17, 2010

Find Value Of 38smith And Wesson Ctgs

properties file in Java (Project Isaacrobot part I)

Hi

Usually in our projects we need to create variables that maybe at some point may come to change and would not be best taken into a database, for this java think a file type called ejemplo.properties in which they can manage properties and values.

The code is as follows:


import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;


/ **
* * @ author mew

* /
FileProperties public class Properties {private properties

;
public void
loadFileProperties (String name) {

properties = new Properties ();
try {
properties.load (this.getClass (). getResource (name + ". properties "). OpenStream ());
} catch (IOException e) {
e.printStackTrace();
}
}

public String getProperty(String property){
String property_= "";
property_ = properties.getProperty(property);
property_=(property_!=null)?property_:"";

return property_;
}

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

FileProperties properties = new FileProperties();
properties.loadFileProperties("baseDeDatos");
System.out.println(""+properties.getProperty("port"));


}


properties file must be on the same path where this class:
for this example would be something like this baseDeDatos.properties and would have the following:


host = localhost port = 1521 sid =

test user = test password = 1234567


The output will be something like this: 1521

0 comments:

Post a Comment