码迷,mamicode.com
首页 > 其他好文 > 详细

golang io.ReadFull

时间:2017-10-23 20:00:56      阅读:278      评论:0      收藏:0      [点我收藏+]

标签:情况   bsp   错误   logs   file   color   style   字节   exp   

	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 。

golang io.ReadFull

标签:情况   bsp   错误   logs   file   color   style   字节   exp   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!