golang io.ReadFull

	buf := make([]byte, 10, 10)
	file, _ := os.Open("./data.txt")
	n, err := io.ReadFull(file, buf)
	if err != nil {
		fmt.Println(n, err.Error())
	} else {
		fmt.Println(n)
	}

  1. 如果 data.txt 是空,则返回 EOF 错误。

      2. 如果 data.txt 少于 10 个字节, 则返回 ErrUnexpectedEOF 错误。并返回读取的字节。

      3. 其他情况,正常返回 10 个字节,错误是 nil 。

原文地址:https://www.cnblogs.com/onebook/p/7718511.html