Article View: borland.public.jbuilder.java.language
Article #17651java.util.Properties use
From: Shannon Brown
Date: Wed, 14 Oct 1998 00:00
Date: Wed, 14 Oct 1998 00:00
92 lines
3158 bytes
3158 bytes
JBuilder 2.0
JDK 1.2b3
JDK 1.1.6
What I am trying to do:
I want to use the java.util.Properties class to save configuration
information to a persistent data file. The properties class allows this
type of saving using and Input or Output Stream.
Some of the information I save is numerical data. For example, I may
save a sequential number called bookID. whenever a book object is
instantiated, the bookID is read from the Properties file, incremented
by one, and then is saved to the Properties file (somewhat similar to an
AutoNumber generator in a database).
Problem:
The Properties Class saves information as a key-value pair as in a hash
table. The problem is: the arguments are Objects(Strings). The number
I increment is a long. I cannot figure out how to save the long integer
to the hashtable and then increment it each time. I have tried casting,
the Long wrapper, etc. and cannot get this to work. I simply want to be
able to save the long int and then retrieve it to increment later. With
String, the incrementing in concatinated rather than added.
CODE SNIPPET
/**
<LI>
bookID = sequentially ordered number assigned to each book
*/
public String getbookletID()
{
return bookletID ;
}
public void setbookletID(String t)
{
bookletID = t ;
}
public void createbookletID()
{
Properties ids = new Properties() ;
try
{
FileInputStream idfile = new FileInputStream("idgenerator.cfg") ;
ids.load(idfile) ;
idfile.close() ;
}
catch (FileNotFoundException e)
{
ids.put("bookletID" , "10") ;
}
catch (IOException e)
{
}
String idseed = ids.getProperty("bookletID") ;
//idseed = idseed + 1 ;
//bookletID = idseed ;
ids.put("bookletID", idseed) ;
bookletID = idseed + 1 ;
try
{
FileOutputStream idfile = new FileOutputStream("idgenerator.cfg") ;
ids.save(idfile, "ID Number Seeds") ;
idfile.close() ;
}
catch (FileNotFoundException e)
{
}
catch (IOException e)
{
}
}
--
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Shannon Brown, President <<< shannon@rubicongulch.com >>>
Rubicon Gulch Software LLC
38 Doe Run Road Suite 260
Manheim PA 17545
http://www.rubicongulch.com
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Technical Details
Message-ID:
<36250D2A.452518E3@rubicongulch.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,dc401e5e7050480f,start X-Google-Attributes: gidf74b3,public From: Shannon Brown <shannon@rubicongulch.com> Subject: java.util.Properties use Date: 1998/10/14 Message-ID: <36250D2A.452518E3@rubicongulch.com> X-Deja-AN: 401108514 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@ptd.net X-Trace: nnrp1.ptd.net 908397970 204.186.18.247 (Wed, 14 Oct 1998 16:46:10 EDT) Organization: PenTeleData http://www.ptd.net MIME-Version: 1.0 NNTP-Posting-Date: Wed, 14 Oct 1998 16:46:10 EDT Newsgroups: borland.public.jbuilder.java.language