设为首页
收藏本站
最近更新

文章搜索
本类热门

 

首页 >> 网络编程 >> JSP >> JSP实例 >> 新闻正文 [字体:  ] [打印文档
用JSP抓取网址

文章作者:
责任编辑: 录入时间:2004-10-13 11:43:36 来源:第七频道
频道声明:本频道的文章除部分特别声明禁止转载的专稿外,可以自由转载.但请务必注明出出处和原始作者 文章版权归本频道与文章作者所有.对于被频道转载文章的个人和网站,我们表示深深的谢意. 

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);
}
}

推荐好友 | 频道收藏 | 打印文档 | 报告错误  
相关连接
·一个完整的上传bean
·不用递归实现论坛树型结构的算法
·JSP中浏览本机目录
·用JSP抓取网址
·产品目录/论坛 树形结构的实现
·Jsp分页实例代码
·在JSP页面中实现检索数据的分页显示
·用JSP+Servlet实现二进制图像的动态显示
同一专题
·无相关专题
发表评论 版权声明:除部分特别声明不要转载,或者授权我站独家播发的文章外,大家可以自由转载我站点的原创文章,但原作者和来自我站的链接必须保留(非我站原创的,按照原来自一节,自行链接)。文章版权归我站和作者共有
转载
要求转载之图片、文件,链接请不要盗链到本站,且不准打上各自站点的水印,亦不能抹去我站点水印。
共有评论查看评论
姓名: