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") file3.WriteString("") } func writeFrist(file3 *os.File, title string) { file3.WriteString("\n") file3.WriteString("\n") file3.WriteString("\t\n") file3.WriteString("\t\t\n") file3.WriteString("\t\t") file3.WriteString(title) file3.WriteString("\n") file3.WriteString("\t\n") file3.WriteString("\t\n") }