Okay, I am a newbie java programmer, and am trying to create some java code to read a configuration file that I have created, and return the results. I will give you the code first, then explain what I am trying to do:
public static String read(String property, File file) throws IOException{
FileInputStream in = new FileInputStream(file);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
String r = "ERROR";
while ((line = br.readLine()) != null) {
if(!line.startsWith("//")){
String[] split = line.split(" ");
if(split[0] == property){
r = split[1];
}
}
}
br.close();
return r;
}
This is what the actual configuration file looks like, where "hello" is the property, and "world" is the value:
hello world
To explain, the desired property is taken as a parameter, as well as the location of theconfiguration file. It will then read each line (ignoring "//") and split it into the property name and value. It will then return the value if it was found, or "ERROR" if the property could not be found.
I then run the following code:
System.out.println(Property.read("hello", new File("config/confix.txt")));
However, every time I run this code, "ERROR" will be printed. I have checked and re-checked my code, and still can't think of what I have done wrong.
Apologies if I have not made myself very clear, so do ask if I need to explain better!