24 lines
389 B
Go
24 lines
389 B
Go
package main
|
|
|
|
import (
|
|
"embed"
|
|
"fmt"
|
|
)
|
|
|
|
//go:embed file/embed.txt
|
|
var embedFile embed.FS
|
|
|
|
func embedFileDemo() {
|
|
// 读取编译嵌入的文件,无磁盘IO操作
|
|
data, err := embedFile.ReadFile("file/embed.txt")
|
|
if err != nil {
|
|
fmt.Printf("读取嵌入文件失败: %v\n", err)
|
|
return
|
|
}
|
|
fmt.Printf("嵌入文件内容: %s\n", string(data))
|
|
}
|
|
|
|
func main() {
|
|
embedFileDemo()
|
|
}
|