Post

GoLangGoLang

i
imran mohammad

Posted on 4th March 2024|14 views

0
votes

Golang Read File To String

How can I read a file to string?

Answers
P
sumana reddy

Posted on 4th March 2024

Here is the example

package main

import (

    "fmt"

    "io/ioutil"

    "log"

)

func main() {

 content, err := ioutil.ReadFile("mindmajix.txt")

    if err != nil {

        log.Fatal(err)

    }

    text := string(content)

    fmt.Println(text)

}

 

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo
  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos