|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
专门做了这个例子;而java的这个例子好像就是为了教学而写的,很多教学目的的例子是不考虑优化、性能的。jsimportjava.io.*;
importjava.net.*;
importjava.util.*;
classurl2htm{
staticprivateurl2htminstance;//Createtheonlyinstanceoftheclass
publicstaticStringstrURL="";//AnnouncetheuniversialvariabletomarkthedestinationURL
publicstaticStringstrFile="";//Announcetheuniversialvariabletomarkthelocalfilepath
/**
*Constructtheprivatefunctiontopreventother
*Applicationfromcreatingtheinstanceofthisclass
*/
privateurl2htm(){
init();
}
/**
*Themainfunctionthatwillinvoketheapplication
*/
publicstaticvoidmain(Stringargs[]){
url2htminstUrl2htm=newurl2htm();//Createtheinstanceofthedefaultclass
instUrl2htm.write();//Invokethechieffunction
}
/**
*ThesetProperties()functionwillsetthetwomajor
*variablestotheclass
*@parapropNames
*@paraname
*/
privatevoidsetProperties(Propertiesprops){
EnumerationpropNames=props.propertyNames();
while(propNames.hasMoreElements()){
Stringname=(String)propNames.nextElement();
if(name.endsWith(".url")){
StringwebName=name.substring(0,name.lastIndexOf("."));
strURL=props.getProperty(webName+".url");
strFile=props.getProperty(webName+".file");
}
}
}
/**
*ThegetURL()functionwillreturntheURLstring
*/
privatevoidgetURL(){
System.out.println(strURL);
}
/**
*ThegetFile()functionwillreturnthelocalfileandpath
*/
privatevoidgetFile(){
System.out.println(strFile);
}
/**
*Thewrite()functionwillreadthedestURLasinputstreamand
*Writeintoalocalfile
*@parafileline
*@paraurl
*/
privatestaticvoidwrite(){
Stringfileline;
Stringurl=strURL;
try{
URLdestURL=newURL(url);
InputStreamin=destURL.openStream();
BufferedReaderfiledata=newBufferedReader(newInputStreamReader(in));
FileOutputStreamout=newFileOutputStream(strFile);
PrintStreamprtStream=newPrintStream(out);
while((fileline=filedata.readLine())!=null){
prtStream.println(fileline+"
");
}
prtStream.close();
}
catch(IOExceptione){
System.out.println("ErrorinI/O:"+e.getMessage());
}
}
/**
*Theinit()functionwillreadthepropertyfileandsetthe
*Classconstants
*@parais:theinputstream
*@parawebProp:thewebsiteproperties
*/
privatevoidinit()
{
InputStreamis=getClass().getResourceAsStream("web.properties");//Datainputstream
PropertieswebProps=newProperties();
try
{
webProps.load(is);
}
catch(Exceptione)
{
System.err.println("Cantreadthepropertyfile."+"Pleasemakesurethepropertyfileisinitspath");
return;
}
setProperties(webProps);
}
}
关于第二点:俺问问你,如果是企业级项目的话,诸如RMI,EJB,等一些关键技术,这些难道都不需要学么?如果光是使用jsp,servlet,javabean的话。 |
|