mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 05:11:49 +08:00
@@ -45,7 +45,7 @@ type Writer interface {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
`fmt.Fprintf()` 依据指定的格式向第一个参数内写入字符串,第一参数必须实现了 `io.Writer` 接口。`Fprintf()` 能够写入任何类型,只要其实现了 `Write` 方法,包括 `os.Stdout`,文件(例如 os.File),管道,网络连接,通道等等,同样的也可以使用 bufio 包中缓冲写入。bufio 包中定义了 `type Writer struct{...}`。
|
`fmt.Fprintf()` 依据指定的格式向第一个参数内写入字符串,第一个参数必须实现了 `io.Writer` 接口。`Fprintf()` 能够写入任何类型,只要其实现了 `Write` 方法,包括 `os.Stdout`,文件(例如 os.File),管道,网络连接,通道等等,同样的也可以使用 bufio 包中缓冲写入。bufio 包中定义了 `type Writer struct{...}`。
|
||||||
|
|
||||||
bufio.Writer 实现了 Write 方法:
|
bufio.Writer 实现了 Write 方法:
|
||||||
|
|
||||||
@@ -53,7 +53,7 @@ bufio.Writer 实现了 Write 方法:
|
|||||||
func (b *Writer) Write(p []byte) (nn int, err error)
|
func (b *Writer) Write(p []byte) (nn int, err error)
|
||||||
```
|
```
|
||||||
|
|
||||||
它还有一个工厂函数:传给它一个 `io.Writer` 类型的参数,它会返回一个缓冲的 `bufio.Writer` 类型的 `io.Writer`:
|
它还有一个工厂函数:传给它一个 `io.Writer` 类型的参数,它会返回一个带缓冲的 `bufio.Writer` 类型的 `io.Writer`:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func NewWriter(wr io.Writer) (b *Writer)
|
func NewWriter(wr io.Writer) (b *Writer)
|
||||||
|
Reference in New Issue
Block a user