Crawl URLs with JSP

Source: Internet
Author: User
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);
}
}



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.