1

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.

2

1 Answer 1

11

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())
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.