forked from go/golangs_learn
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
971 B
48 lines
971 B
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"time"
|
|
)
|
|
|
|
func main() {
|
|
fmt.Println("关于生成HTML")
|
|
//获取当前目录
|
|
path, _ := filepath.Abs("./")
|
|
path = path + "\\结构对比-" + time.Now().Format("2006102150405") + ".html"
|
|
|
|
//创建文件
|
|
//Create函数也是调用的OpenFile
|
|
file3, _ := os.Create(path)
|
|
|
|
title := "1234"
|
|
//写入头部份
|
|
writeFrist(file3, title)
|
|
|
|
//写入内容
|
|
file3.WriteString(path)
|
|
|
|
//写入尾部份
|
|
writeList(file3)
|
|
|
|
//关闭文件
|
|
file3.Close()
|
|
}
|
|
func writeList(file3 *os.File) {
|
|
file3.WriteString("\t</body>")
|
|
file3.WriteString("</html>")
|
|
}
|
|
|
|
func writeFrist(file3 *os.File, title string) {
|
|
file3.WriteString("<!DOCTYPE html>\n")
|
|
file3.WriteString("<html>\n")
|
|
file3.WriteString("\t<head>\n")
|
|
file3.WriteString("\t\t<meta charset=\"utf-8\">\n")
|
|
file3.WriteString("\t\t<title>")
|
|
file3.WriteString(title)
|
|
file3.WriteString("</title>\n")
|
|
file3.WriteString("\t</head>\n")
|
|
file3.WriteString("\t<body>\n")
|
|
}
|
|
|