📄 savehtml.java
字号:
package admin;
import java.io.*;
import java.util.Date;
import java.text.SimpleDateFormat;
public class SaveHTML {
private String author="";
private String title="";
private String keywords="";
private String content="";
private String updateTime="";
private String typeid="";
private String filePath="";
private String dirPath="";
private String templateContent="";
private String saveDirectory="";
private String htmlName="";
private String saveStr="";
private String fileSize="";
public void setElement(String dirPath,String keywords,String title,String updateTime,String content,String userName,String filePath,String typeid){
this.dirPath=dirPath;
this.keywords=keywords;
this.title=title;
int typeInt=Integer.parseInt(typeid);
if(typeInt==6){String [] str=updateTime.split(",");this.updateTime=str[0];this.fileSize=Integer.toString((Integer.parseInt(str[1]))/1024);}
else this.updateTime=updateTime;
this.content=content;
this.author=userName;
this.filePath=filePath;
this.typeid=typeid;
//得到保存的目录名
switch(typeInt){
case 1:saveDirectory="xueyuan";saveStr="学院概况";break;
case 2:saveDirectory="dangjian";saveStr="党建工作";break;
case 3:saveDirectory="keyan";saveStr="科学研究";break;
case 4:saveDirectory="jiaoxue";saveStr="教学工作";break;
case 5:saveDirectory="xuesheng";saveStr="学生工作";break;
case 6:saveDirectory="xiazai";saveStr="常用下载";break;
case 7:saveDirectory="shiyan";saveStr="实验活动";break;
}
}
public String getSaveDircetory(){ //得到html的保存目录
return saveDirectory;
}
public String getHtmlName(){ //得到html的保存名
return htmlName;
}
public String getSaveStr(){ //得到所属类别
return saveStr;
}
public String getTemplateContent(){ //得到文章内容
return templateContent;
}
public void setTemplateContent() throws Exception{//替换模块中的相应内容
String myTime=new java.text.SimpleDateFormat("yyMMddHHmmssS").format(new java.util.Date());
htmlName=myTime+".html";
FileInputStream fileinputstream = new FileInputStream(filePath);//读取模块文件
int lenght = fileinputstream.available();
byte bytes[] = new byte[lenght];
fileinputstream.read(bytes);
fileinputstream.close();
templateContent = new String(bytes);
//替换模块中的相应内容
templateContent=templateContent.replaceAll("###keywords###",keywords);
templateContent=templateContent.replaceAll("###title###",title);
templateContent=templateContent.replaceAll("###fileSize###",fileSize);
templateContent=templateContent.replaceAll("###otime###",updateTime);
templateContent=templateContent.replaceAll("###ArticleContent###",content);
templateContent=templateContent.replaceAll("###fileName###",keywords);
templateContent=templateContent.replaceAll("###author###",author);
}
public void saveHtmlFile() throws Exception{
String fileName = dirPath+"content/"+saveDirectory+"/"+htmlName;//生成的html文件保存路径
FileOutputStream fileoutputstream = new FileOutputStream(fileName);//建立文件输出流
byte tag_bytes[] = templateContent.getBytes();
fileoutputstream.write(tag_bytes);
fileoutputstream.close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -