dqst96444 2018-08-24 18:56
浏览 191
已采纳

在Golang中读取二进制.fbx文件

Unlike in other languages, I really couldn't figure out how to read a binary file into an array of bytes or just turn it into an ASCII-string, which puts me into quite a problem.

The code I've been using:

func TestFBX(fileName string) {
    file, err := os.Open(fileName)
    if (err != nil) {
        log.Fatal(err)
    }
    defer file.Close()

    var content []byte
    scanner := bufio.NewScanner(file)
    for scanner.Scan() {
        text := []byte(scanner.Text())
        buf := bytes.NewReader(text)
        err := binary.Read(buf, binary.LittleEndian, &content)

        if (err != nil) {
            fmt.Println(err)
        }
    }

    fmt.Printf("%v", content)
    fmt.Println("")

    if err := scanner.Err(); err != nil {
        log.Fatal(err)
    }
}

What it does in the end is print out [ ], an empty slice. Now when I tried putting float64 or int32 instead of []byte it did print out different numbers but I still honestly don't get how to read the whole file and not just whatever number is there at the beginning.

  • 写回答

2条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 在matlab中如何进行三个参数的离散傅里叶逆变换(idft)
      • ¥15 遇到问题了,求解答!
      • ¥15 请问coppliasim eduUR5视觉抓取怎么实现仿真,
      • ¥30 JavaWeb实验(购物平台)
      • ¥15 八路抢答器倒计时设计时显示器不输出,只能显示0
      • ¥15 用C语言随机生成一个迷宫
      • ¥15 超多因素的正交方案设计
      • ¥15 Scratch~汽车小游戏
      • ¥30 OSGB转换为3dtiles
      • ¥25 用于Audio的芯片中“Audio Interface”和“Mode Control”是什么?