import java.io.*;
import java.net.*;
import java.util.*;
class url2htm{
static private url2htm instance; // create the only instance of the class
public static string strurl=””; // announce the universial variable to mark the destination url
public static string strfile=””; // announce the universial variable to mark the local file path
/**
* construct the private function to prevent other
* application from creating the instance of this class
*/
private url2htm(){
init();
}
/**
* the main function that will invoke the application
*/
public static void main(string args[]){
url2htm insturl2htm = new url2htm(); // create the instance of the default class
insturl2htm.write(); // invoke the chief function
}
/**
* the setproperties() function will set the two major
* variables to the class
* @para propnames
* @para name
*/
private void setproperties(properties props){
enumeration propnames = props.propertynames();
while(propnames.hasmoreelements()){
string name = (string) propnames.nextelement();
if(name.endswith(“.url”)){
string webname = name.substring(0,name.lastindexof(“.”));
strurl = props.getproperty(webname + “.url”);
strfile = props.getproperty(webname + “.file”);
}
}
}
/**
* the geturl() function will return the url string
*/
private void geturl(){
system.out.println(strurl);
}
/**
* the getfile() function will return the local file and path
*/
private void getfile(){
system.out.println(strfile);
}
/**
* the write() function will read the dest url as input stream and
* write into a local file
* @para fileline
* @para url
*/
private static void write(){
string fileline;
string url = strurl;
try {
url desturl = new url(url);
inputstream in = desturl.openstream();
bufferedreader filedata = new bufferedreader(new inputstreamreader(in));
fileoutputstream out = new fileoutputstream(strfile);
printstream prtstream = new printstream(out);
while ((fileline = filedata.readline()) != null) {
prtstream.println(fileline + “\n”);
}
prtstream.close();
}
catch (ioexception e) {
system.out.println(“error in i/o:” + e.getmessage());
}
}
/**
* the init() function will read the property file and set the
* class constants
* @para is: the input stream
* @para webprop: the web site properties
*/
private void init()
{
inputstream is = getclass().getresourceasstream(“web.properties”); // data input stream
properties webprops = new properties();
try
{
webprops.load(is);
}
catch (exception e)
{
system.err.println(“cant read the property file. ” + “please make sure the property file is in its path”);
return;
}
setproperties(webprops);
}
}
