Java Reference
In-Depth Information
favorite_programming_language=Java
pencil_color green
Fortunately, when a Properties object writes itself to a file, it uses the simple format:
key=value
Here is an example of a program that creates a Properties object and adds into it the list of
companies and their locations from Mapping with Hashtable and HashMap . It then loads ad-
ditional properties from disk. To simplify the I/O processing, the program assumes that the
Properties file to be loaded is contained in the standard input, as would be done using a
command-line redirection on either Unix or DOS:
public
public class
class PropsCompanies
PropsCompanies {
public
public static
static void
void main ( String [] argv ) throws
throws java . io . IOException {
Properties props = new
new Properties ();
// Get my data
props . put ( "Adobe" , "Mountain View, CA" );
props . put ( "IBM" , "White Plains, NY" );
props . put ( "Learning Tree" , "Los Angeles, CA" );
props . put ( "Microsoft" , "Redmond, WA" );
props . put ( "Netscape" , "Mountain View, CA" );
props . put ( "O'Reilly" , "Sebastopol, CA" );
props . put ( "Sun" , "Mountain View, CA" );
// Now load additional properties
props . load ( System . in );
// List merged properties, using System.out
props . list ( System . out );
}
}
Running it as:
java structure.PropsCompanies < PropsDemo.out
Search WWH ::




Custom Search