O'Reilly logo

Sams Teach Yourself Java™ in 24 Hours, Sixth Edition by Rogers Cadenhead

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Reading and Writing Configuration Properties

Java programs are more versatile when they can be configured using command-line arguments, as you have demonstrated in several applications created in preceding hours. The java.util package includes a class, Properties, that enables configuration settings to be loaded from another source: a text file.

The file can be read like other file sources in Java:

• Create a File object that represents the file.

• Create a FileInputStream object from that File object.

• Call load() to retrieve the properties from that input stream.

A properties file has a set of property names followed by an equal sign (=) and their values. Here’s an example:

username=leptonlastCommand=open databasewindowSize=32

Each property ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required