doujia2021 2017-02-02 01:13
浏览 75

从Reader.Read()读取时如何正确清除字节数组

I'm trying to read bytes from a src using Reader.Read but when I print out the data I'm noticing random characters interspersed throughout the output at the beginning of lines which makes me think I'm not clearing the buffer correctly but I'm not sure how to do it being new to Go.

numRead := 1
for numRead > 0 {
    p := make([]byte, 100)
    numRead, _ = hijack.Reader.Read(p) //hijack is a struct that points to a reader
    p = p[:numRead]
    fmt.Printf("%s", p)
}

Some lines come out okay like

Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/mojo/plugin-support/1.0-alpha-1/plugin-support-1.0-alpha-1.pom (5 KB at 25.1 KB/sec)

Others will have a character at the beginning like this

hDownloaded: https://repo.maven.apache.org/maven2/org/apache/apache/4/apache-4.pom (5 KB at 27.4 KB/sec)

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 孟德尔随机化r语言运行问题
    • ¥15 pyinstaller编译的时候出现No module named 'imp'
    • ¥15 怎么把多于硬盘空间放到根目录下
    • ¥15 Matlab问题解答有两个问题
    • ¥50 Oracle Kubernetes服务器集群主节点无法访问,工作节点可以访问
    • ¥15 LCD12864中文显示
    • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
    • ¥15 gsoap生成onvif框架
    • ¥15 有关sql server business intellige安装,包括SSDT、SSMS。
    • ¥15 stm32的can接口不能收发数据