GO语io包的常用接口

2019-11-10 09:09:04于海丽

SEEK_CUR int = 1 //从文件的指针的当前位置处开始设置 offset
SEEK_END int = 2 //从文件的末尾处开始设置 offset
六、io.Closer

定义:
type Closer interface {
    Close() error
}
用于关闭数据流,释放资源,不用多废话了吧。

七、其他
type ByteReader interface {
 ReadByte() (c byte, err error)
}

type RuneReader interface {
    ReadRune() (r rune, size int, err error)
}
ReadByte读取输入中的单个字节并返回。如果没有字节可读取,会返回错误。
ReadRune读取单个utf-8编码的字符,返回该字符和它的字节长度。如果没有有效的字符,会返回错误。
type ByteWriter interface {
    WriteByte(c byte) error
}
WriteByte写入一个字节,如果写入失败会返回错误。

参考:
https://gowalker.org/io
https://github.com/polaris1119/The-Golang-Standard-Library-by-Example/blob/master/chapter01/01.1.md

希望本文所述对大家的GO语言程序设计有所帮助。