One way to do is to use the properties file and use the StringTokenizer
class to extract the key values.

sample.properties

<Key>                   <Values>
languages       Lisp Prolog Java

The key-values are separated by StringTokenizer default delimiters (In this
case blank).

In the code, we can write

String theLanguages = theProps.getProperty( "languages");
StringTokenizer theLangList = new StringTokenizer( theLanguages);

java.util.Vector theLangsVector = new java.util.Vector();

while ( theLangList.hasMoreElements() ) {
   String theLanguage = theLangList.nextToken().trim();
   theLangsVector.addElement( theLanguage );
}


Sree Pillai

>From: Rajendran, Rajarajan
><[EMAIL PROTECTED]>
>Reply-To: "A mailing list for discussion about Sun Microsystem's Java
>        Servlet API Technology." <[EMAIL PROTECTED]>
>To: [EMAIL PROTECTED]
>Subject: RE: properties file to Hashtable.
>Date: Tue, 30 May 2000 08:59:24 -0500
>
>Well, I did that. Anyway thank you.
>
>I have a different but related doubt. You can only read key-value pairs
>from a properties file. In case if there are two or three simple values
>(instead of just one in properties file) for every key, how can you store
>and read from a simple file (possibly a text file ?) (without going for
>tables/database). This has to be loaded in a right data structure and has
>to be retrieved.
>
>Say for example, id=1,kevin,23
>                  id=2,mukar,32
>
>Please tell me the following approach is right ?
>
>Read it as a properties file and after that by using StringTokenizer "," ,
>we can get the individual values.
>
>Is there any other better approach ?
>
>Regards
>
>Raj
>-----Original Message-----
>From: Kevin Mukhar [mailto:[EMAIL PROTECTED]]
>Sent: Friday, May 26, 2000 11:31 AM
>To: [EMAIL PROTECTED]
>Subject: Re: properties file to Hashtable.
>
>
>"Rajendran, Rajarajan" wrote:
> >
> > I want to read a .properties file through a servlet and get the
>properties
> > and
> > set it to a Hashtable. Can anyone please help me out by sample code.
>
>Have you read the javadoc for Properties and Hashtable yet? Normally that
>should
>be enough to answer your question. If you have read the docs, are you
>having
>a
>specific problem?
>
>First create property file using an editor
>
>Here's pseudo code showing one way to get properties:
>
>create instance of java.io.FileInputStream from property file
>create instance of java.util.Properties
>call Properties.load(InputStream) method to load properties
>call Properties.propertyNames() to get Enumeration of all names
>loop through Enumeration of names
>   call getProperty(name) to get a property
>   if you really want to, store name/property in hashtable
>
>Why are you wanting to store the properties in a Hashtable? Since the
>Properties
>class already stores properties for you using a key-value approach,
>creating
>a
>Hashtable to store the properties is redundant.
>
>K Mukhar
>
>___________________________________________________________________________
>To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
>of the message "signoff SERVLET-INTEREST".
>
>Archives: http://archives.java.sun.com/archives/servlet-interest.html
>Resources: http://java.sun.com/products/servlet/external-resources.html
>LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
>___________________________________________________________________________
>To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
>of the message "signoff SERVLET-INTEREST".
>
>Archives: http://archives.java.sun.com/archives/servlet-interest.html
>Resources: http://java.sun.com/products/servlet/external-resources.html
>LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to