mysql 6
来源:互联网 发布:linux内核内存管理浅析 编辑:程序博客网 时间:2024/06/03 18:27
private NewsDao dao = new NewsDaoImpl();
//定义dao对象 得到 newimple l类的方法
public void replaceContent(){
String path = "d:/html/";
// D盘下 html 文件
String templateContent = FileUtil.readFile(path + "template.html", "GBK");
利用 readline 读取文件内容
System.out.println(templateContent);List<News> list = dao.getNews();
//getNews方法得到日期得到得到文章标题内容和作者
//把数据库的新闻内容通过循环写入到html文件中for(News n : list){
String content = templateContent.replace("#{title}", n.getTitle()).
replace("#{author}", n.getAuthor()).
replace("#{date}", n.getPublishDate()).
replace("#{content}", n.getContent());
// System.out.println(content);
FileUtil.writeFile(content, path + n.getTitle() + ".html");
}
}
public class FileUtil {
public static String readFile(String fileName){
FileReader fr = null;
BufferedReader br = null;
StringBuffer sb = new StringBuffer();
try {
fr = new FileReader(fileName);
// 读取名字为Filename 的文件
br = new BufferedReader(fr);
String tmp = br.readLine();
//zhenhan
while(tmp != null){
sb.append(tmp).append("\r\n");
//利用StringBuffer 类中的 Append 方法 链接tmp
tmp = br.readLine();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
if(br != null){
br.close();
}
if(fr != null){
fr.close();
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
return sb.toString();
}
public static String readFile(String fileName, String charSet){
FileInputStream fis = null;
InputStreamReader isr = null;
BufferedReader br = null;
StringBuffer sb = new StringBuffer();
try {
fis = new FileInputStream(fileName);
isr = new InputStreamReader(fis,charSet);
br = new BufferedReader(isr);
String tmp = br.readLine();
while(tmp != null){
sb.append(tmp).append("\r\n");
tmp = br.readLine();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
if(br != null){
br.close();
}
if(isr != null){
isr.close();
}
if(fis != null){
fis.close();
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
return sb.toString();
}
需要写入文件的内容
public static void writeFile(String content, String fileName){
FileWriter fw = null;
BufferedWriter bw = null;
try {
fw = new FileWriter(fileName);
bw = new BufferedWriter(fw);
bw.write(content);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
if(bw != null){
bw.close();
}
if(fw != null){
fw.close();
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
public static void main(String[] args) {
String c = FileUtil.readFile("d:/html/template.html");
//度文件
FileUtil.writeFile(c, "d:/html/t1.html");
//写入文件
System.out.println("tesk ok");
}
}
- mysql 6
- MySQL心得6--MySQL语言结构--函数
- mysql学习之--6、mysql时间类型
- mysql笔记-- mysql命令札记6
- MySQL详解(6)---------MySQL语句
- MySQL学习6:MySQL基本数据类型
- python3.6 mysql django mysql-python
- Mysql 数据库优化6
- php +mysql 6
- MySQL Server 6 安装
- 6、MySQL-删除数据库
- (6)mysql中的字符集
- mysql 高可用6
- VS2012+EntityFramework 6+mysql
- Python3.6连接MySQL
- MySQL(6):约束
- Python3.6连接MySQL
- Mac 10.11.6 Mysql
- 继承
- 生成排列(Generating Permutations, UVa11925)
- 使用Python求解最大公约数
- MYSQL
- 推送消息总结
- mysql 6
- 百元白鸡问题
- 关于Android线性布局与滚动实现
- java变量和数据类型
- 461. Hamming Distance
- CSS选择器,属性前缀,长度单位,变形效果,过渡效果,动画效果
- 微信h5点击放大全屏看图片
- TypeScript笔记
- 线索化二叉树