Can a property from a .properties file be made into a usable variable?

WinJake

New member
Local time
1:09 AM
Messages
21
I have code to read out lines from .properties, but it just prints it out, because im an idiot and didn't notice till now. So, the question is, can it be made into a variable instead?
current code;
Code:
Properties prop = new Properties();
	InputStream input = null;
	try {
		input = new FileInputStream("config.properties");
		prop.load(input);
		System.out.println(prop.getProperty("CyclesTime"));
		System.out.println(prop.getProperty("NmbOfCycles"));
		System.out.println(prop.getProperty("MsgForSave"));
		System.out.println(prop.getProperty("MsgForRestart"));}
		catch (IOException ex) {ex.printStackTrace();}
			finally {
				if (input != null) {
					try { input.close();} 
						catch (IOException e) {e.printStackTrace();} } }
And anything wrong with the code while I'm asking?
 

My Computer My Computer

Computer Manufacturer/Model Number
Toshiba Satellite L755
OS
Windows 7 Home Premium 64bit
Memory
500 GB
Of course, you're reading and outputting to console immediately, so it can't be of further use. Just assign it to a variable instead. Something like that will do:

Code:
int nmbOfCycles = (int)prop.getProperty("CyclesTime");
System.out.println(nmbOfCycles);                         //here it prints the variable with the property value
//further usage of the same property can be done on the variable

Note that I have not tested it, and I don't have really many Java skills, but the idea is that, save to a variable first, then use the variable as many times as you want.
 

My Computer My Computer

Computer type
Laptop
Computer Manufacturer/Model Number
Toshiba Sattelite A665-S6092
OS
Windows 7 Ultimate x64
CPU
Intel Core i7-740QM
Memory
8 GB DDR3
Graphics Card(s)
NVIDIA GeForce 330GT
Screen Resolution
1366x768
Hard Drives
Samsung 840 SSD 500GB
1TB USB3 external HD
Cooling
Coolermaster Notepal U3 notebook cooling pad
Internet Speed
3mbps ASDL
Antivirus
ClamWin 0.98.7
Browser
Opera 12.17 x86 (main), Firefox 38 (sec), IE11 (last resort)
Back
Top