How do I read in a large flat file

后端 未结 4 1326

I have a flat file that has 339276 line of text in it for a size of 62.1 MB. I am attempting to read in all the lines, parse them based on some conditions I have and then insert

4条回答
  •  梦谈多话
    2021-02-05 17:59

    package main
    
    import (
        "fmt"
        "os"
        "log"
        "bufio"
    )
    
    func main() {
        FileName := "assets/file.txt"
        file, err := os.Open(FileName)
        if err != nil {
            log.Fatal(err)
        }
        defer file.Close()
    
        scanner := bufio.NewScanner(file)
    
        for scanner.Scan() { 
            fmt.Println(scanner.Text()) 
    
        }
    }
    

提交回复
热议问题