用JSP抓取网址
2008-02-23 09:37:25来源:互联网 阅读 ()
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("Can''t read the property file. " "Please make sure the property file is in its path");
return;
}
setProperties(webProps);
}
}
上一篇: 产品目录/论坛 树形结构的实现
下一篇: Jsp分页实例代码
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:Pointcut的学习(一)
下一篇:Groovy Notes
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash