PDA

View Full Version : Anyone know java properties?


jcrox
10-07-07, 10:48 AM
I need to output to the console the contents of a properties file and I'm lost... please help!!!

Heres my code so far:

package java112.labs2;

import java.util.*;
import java.io.*;

public class LabTwoThree {

private Properties props;
private String propsFile;

public void run(String propsFile) {

this.propsFile = propsFile;
loadProps();
What do I put in here to get the info in the properties file to output to the console?
}

public void loadProps() {
props = new Properties();
try {
props.load(this.getClass().getResourceAsStream(pro psFile));
}
catch(IOException ioe) {
System.out.println("Can't load the properties file");
ioe.printStackTrace();
}
catch(Exception e) {
System.out.println("Problem: " + e);
e.printStackTrace();
}



public static void main(String[] args) {
LabTwoThree go = new LabTwoThree();
go.run(args[0]);


}
}
}

jcrox
10-07-07, 02:31 PM
update:

heres my set up:

projects
- classes
---java112
----analyzer
-----labs1
-----labs2
- config
- data
- docs
- output
- public_html
- src
--- java112
------analyzer
------labs1
------labs2
------project2
------tests
------util

Ok, with the program in the above post I need to read the information from the labs2-3.properties file located in the config folder.... I can get it to compile just fine but no matter what I do I get a NullPointerException :(
Here's the .bat file I'm using to try and run this... hopefully some java guru can help me

"C:\Program Files\java\jdk1.6.0_02\bin\java.exe" -classpath classes;config java112.labs2.LabTwoThree "config/lab2-3.properties"

jcrox
10-07-07, 03:53 PM
it works now :D