0

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(); } } 
5
  • are you sure that the file you read is exactly the file you wrote? Commented Oct 12, 2016 at 22:17
  • What is the value of "PVIDIdentifyLocation"? Commented Oct 12, 2016 at 22:23
  • "C://PALMUS-PV/PVInfo.ini" should be "C:/PALMUS-PV/PVInfo.ini" Commented Oct 12, 2016 at 22:29
  • @GuyBouallet yes Sir. Commented Oct 12, 2016 at 22:33
  • @JoopEggen output still null Sir. Commented Oct 12, 2016 at 22:33

1 Answer 1

1

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"); 
Sign up to request clarification or add additional context in comments.

5 Comments

Thank you for your response Sir. Change PV-ID --> pvid and PALMUS-ID --> palmusid, output still null.
Your response is unclear. Both keys must match. The key you need to reference in both places is either ("PVIDNo", "SerialNo") OR ("PV-ID", "PALMUS-ID")
See my edit. You've simply used the wrong key names to retrieve the values from the property file object
Now I get it. Thank you so much Sir!
You're welcome. It's easy to get strings and variable names confused

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.