我正在使用 fmt.Fprintf(file, "<string>")
,但在一个函数中。我使用 xmlFile :=
创建新文件在主函数中,然后将该变量传递给写入文件的函数的调用,但我收到文件参数错误,它没有类型。我应该给它什么类型的?
它不是一个字符串,它是一个文件。
文件是什么类型的?
下面是函数的定义:
func processTopic(id string, properties map[string][]string, file){
最佳答案
来自 the documentation :
func Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error)
Fprintf 接受一个io.Writer
。 io.Writer
是一个接口(interface),这意味着您可以传递任何实现它的类型。这包括*os.File
(系统文件)和*bytes.Buffer
(内存)。
关于go - 在 Go 中,当我使用 fmt.Printf 时文件是什么类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23070221/