jweinst1
12/25/2016 - 9:05 AM

using file io with command line arguments

using file io with command line arguments

package main

import (
   "fmt"
   "io/ioutil"
   "os"
)

func main() {
	userArgs := os.Args[1:]

    b, err := ioutil.ReadFile(userArgs[0]) // just pass the file name
    if err != nil {
        fmt.Print(err)
    }

    fmt.Println(b) // print the content as 'bytes'

    str := string(b) // convert content to a 'string'

    fmt.Println(str) // print the content as a 'string'
}