我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

golang逐行读取

I've started studying golang a bit and I'm absolutely unable to understand how I'm supposed to read line by line in the old-fashioned way:

while filehandler != EOF {
line_buffer = readline(filehandler)
}

I'm aware that I have to use bufio scanlines. This isn't what I am using as code, I'm merely trying to explain the idea.

use this:

package main

import (
    "bufio"
    "fmt"
    "os"
)

func main() {
    file, _ := os.Open("path/to_file")
    fscanner := bufio.NewScanner(file)
    for fscanner.Scan() {
        fmt.Println(fscanner.Text())
    }
}

近期文章

  • Golang net.ListenTCP结构
  • 相等的指针是否不同?
  • 在Golang中返回接口
  • mgo查询针对大型数据集返回“ EOF”
  • http ResponseWriter重复答案golang
  • golang是否可以将参数数量未知的函数作为另一个函数的参数
  • 进入频道非阻塞多个接收
  • 接口指针作为函数参数
  • 这里是否生成某种构造函数?
  • 如果条件导致编译错误,为什么要加括号?
  • 如何在Go中使用清晰的结构值优化性能?
  • 去操场#23返回问题
  • Go中的len(string)和len(slice)的O(1)操作吗?
  • 如何使用Go将这个JSON数组解组到结构切片中?
  • 相当于ansi c raise()的golang
  • 如何使用反射将值分配给嵌套结构
  • Golang big.Float的精度问题
  • 扩展库的结构/接口
  • 如何在没有bug的情况下通过按键编写互斥锁?
  • 为什么Go的encoding / xml.Decoder.Token()不会像应有的那样生成xml.Attr令牌?

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华