Java Reference
In-Depth Information
# my property file containing runtime file names
inputfile=testin.fil
outputfile=testout.fil
The file has two properties: inputfile and outputfile . The line with the # is
simply a comment. To load the properties, you write code like this:
Properties props = new Properties();
props.load(new FileInputStream("myproperties.prop"));
Once the properties are loaded, you can access them like this:
// returns "testin.fil"
String inputFilename = props.getProperty("inputfile");
// returns "testout.fil"
String outputtFilename = props.getProperty("outputfile");
Using this technique, the program could go into production and use produc-
tion files simply by editing the properties file.
J AVA U TILITIES
Java provides a number of utilities to assist in your development processes. I'll
cover a few here.
J AR U TILITY
The Java Archive utility is used for bundling classes, images, and other resources that
compose a Java project. The Java Archive utility was discussed in Chapter 2 from the
standpoint of a user of a jar file. Here I'm going to discuss how to create one.
Internally, a jar file is much like a zip file. It contains entries for files and direc-
tories, and it contains the compressed content of the files. Packaging applications
in jar files simplifies distribution and reduces the network load when classes are
passed over the Internet or through a network.
There are two primary differences between a jar file and a zip file: A jar file can
be signed with a digital signature to provide security and authentication, and a jar
file contains a manifest that carries information about the content of the file and
how it is to be handled.
The jar utility program comes with the SDK. It is the tool used to create and
manage jar files. Like the rest of the SDK, it must be run from a DOS command
window. The simplest format for using the jar program is as follows:
Search WWH ::




Custom Search