9951 explained code solutions for 126 technologies

golangHow to read file to string

package main

import (

func main() {
  t, _ := os.ReadFile("/var/www/examples/test.txt")
  str := string(t)
}ctrl + c
package main

default package declaration


include operating-system level library

func main() {

declare main function that will be launched automatically


read contents from specified file


file to read


string variable will contain contents from file


convert given variable to string