Js
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 destination URL of the universial variable to mark
public static String strfile= ""; Announce the universial variable to mark's local file path
/**
* Construct the private function to prevent
* Application from creating the instance of this class
*/
Private url2htm () {
Init ();
}
/**
* The main function that would 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 would 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 would return the URL string
*/
private void GetURL () {
System.out.println (strURL);
}
/**
* The GetFile () function would return to the local file and path
*/
private void GetFile () {
System.out.println (strfile);
}
/**
* The Write () function would 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 would 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 ("Can" T read the property file. "+" Sure "" "" "" "" to Make the "" "" to "" "to" ".
Return
}
SetProperties (Webprops);
}
}