英文:
Golang size of []byte in int64
问题
length 是 int 类型的。我需要找到 int64 类型的长度。我只有文件的 []byte 数据。如何找到 int64 类型的数据大小呢?
英文:
//data = file in []byte
length := len(data)
length is in type int. I need to find the length in int64. I only have the []byte data of the file. How can I find the size of data in int64?
答案1
得分: 8
将int转换为int64:
l := int64(len(data))
切片的长度保证适合于int类型。如果文件的大小超过了int类型所能表示的范围,那么就无法将整个文件读入[]byte中。
英文:
Convert the int to an int64:
l := int64(len(data))
The length of a slice is guaranteed to fit in an int. If the file is larger than what can be represented by an int, then it's not possible to read the entire file into a []byte.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论