• java生成html页面


    package com....;
    
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import com.alibaba.fastjson.JSONObject;
    
    public class HtlmInfo {
        
        private static String filePath = "D:\eclipse-workspace\ac-product-net\WebRoot\item\table.html";//模板地址
        private static String disrPath = "D:\eclipse-workspace\ac-product-net\WebRoot\item\";//生成路径
        private static String fileName = ".html";
        
        //json为填充页面数据
        public static void MakeHtml(JSONObject json){
            try {
            String templateContent = "";
            FileInputStream fileinputstream = new FileInputStream(filePath);// 读取模板文件
            int lenght = fileinputstream.available();
            byte bytes[] = new byte[lenght];
            fileinputstream.read(bytes);
            fileinputstream.close();
            templateContent = new String(bytes);
            String title = json.getString("title");
            String publishtime = json.getString("publish_time");
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy 年 MM 月 dd 日 ");
            String publish_time= sdf.format(new Date(Long.parseLong(String.valueOf(publishtime))));
            System.out.println("时间转换:" + publish_time+"
    ");
          //把模板页面上的 ###text### 替换成 title 里的内容
            templateContent = templateContent.replaceAll("###title###", title);
            templateContent = templateContent.replaceAll("###publish_time###", publish_time);
    //        System.out.print(templateContent);
            String fileame = title+fileName;
            fileame = disrPath + fileame;// 生成的html文件保存路径。
            FileOutputStream fileoutputstream = new FileOutputStream(fileame);// 建立文件输出流
            System.out.print("文件输出路径:");
            System.out.print(fileame);
            byte tag_bytes[] = templateContent.getBytes();
            fileoutputstream.write(tag_bytes);
            fileoutputstream.close();
            } catch (Exception e) {
            System.out.print(e.toString());
            }
        }
        
    }
  • 相关阅读:
    Create a toolwindow for the VBA editor with .NET(C#).
    批量采集世纪佳缘会员图片及winhttp异步采集效率
    写了一个Windows API Viewer,提供VBA语句的导出功能。提供两万多个API的MSDN链接内容的本地查询
    mysql主从复制
    windows实现MySQL主从复制
    理解“业务逻辑”的含义
    数据库主从复制与读写分离(了解)
    windows下npm安装vue
    phpstorm中配置真正的远程调试(xdebug)
    PHP常量详解:define和const的区别
  • 原文地址:https://www.cnblogs.com/lifan12589/p/13901076.html
Copyright © 2020-2023  润新知