Reputation: 461
I've been trying to put the data inside my ini file on a String after I write it, but somehow the output of the string is null. But when I check the ini file, it has value in it. I'm not sure if it's about the file path but I just copied the path in the directory. I hope someone can help me, newbie here. Thank you.
common.writeIniFileIdentify("PV-ID", PVIDNo); // PsFileAccessorIni.GetInstance().GetValueString(PsFileAccessorIni.PVIDLocation));
common.writeIniFileIdentify("PALMUS-ID", SerialNo);// PsFileAccessorIni.GetInstance().GetValueString(PsFileAccessorIni.PVIDLocation));
Properties p = new Properties();
p.load(new FileInputStream("C://PALMUS-PV/PVInfo.ini"));
String pvid = p.getProperty("PVIDNo");
String palmusid = p.getProperty("SerialNo");
System.out.println(pvid);
System.out.println(palmusid);
Here's the writeIniFileIdentify:
public void writeIniFileIdentify(String key, String value) {
try {
Properties props = new Properties();
props.load(new FileInputStream(PVIDIdentifyLocation));
props.setProperty(key, value);
props.store(new FileOutputStream(PVIDIdentifyLocation, false), null);
} catch (Exception ex) {
ex.printStackTrace();
}
}
Upvotes: 0
Views: 257
Reputation: 685
Are you closing the file and releasing the resource after re-loading it and reading the property back out?
Also, the keys you are using to pull out the values are different than the keys you've used to write to the file with. The keys you are referencing in the file:
String pvid = p.getProperty("PVIDNo");
String palmusid = p.getProperty("SerialNo");
Do not match the keys you've written:
common.writeIniFileIdentify("PV-ID", PVIDNo);
common.writeIniFileIdentify("PALMUS-ID", SerialNo);
If you want to stick with the keys you've written, retrieve the property values like this:
String pvid = p.getProperty("PV-ID");
String palmusid = p.getProperty("PALMUS-ID");
Upvotes: 1