dcsimg
Reading Key-value pairs from a flat file
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Sandy_Sanya
Posted On:   Monday, April 7, 2003 08:50 AM

			
How to read Key-value from text file and use in a program

Re: Reading Key-value pairs from a flat file

Posted By:   Jonathan_Downey  
Posted On:   Tuesday, April 8, 2003 02:48 AM

Please don't ask the same question twice at the same time. It discourages people from bothering with the Forums if they're full of duplicate questions.


Here's a code snippet:


public Properties loadProps(String fileName) throws Exception {
Properties props = null;
FileInputStream istr = null;
try{
istr = new FileInputStream( fileName );
props = new Properties();
props.load( istr );
} finally {
if(istr!=null)
istr.close();
}
return props;
}

You can use
props.getProperty( keyName )
to read a value. Your Properties file has values like



#This is a sample Properties File
username=jdowney
password=somepassword
folder=c:\test

Note the \ when specifying folder names (Windows, obviously).


Oh, and "Read the documentation" is a pretty lame answer. Don't answer if that's your response. There's a shed-load of documentation in the API. At least mention the class that the person asking the question needs.


Jonathan.

Re: Reading Key-value pairs from a flat file

Posted By:   Zac_Jacobson  
Posted On:   Monday, April 7, 2003 12:18 PM

Please try reading some documentation.

About | Sitemap | Contact