Working with Files
Read File to String
package golang
import (
"io/ioutil"
)
func FileToString(filepath string) string {
bits, e := ioutil.ReadFile(filepath)
if e != nil {
panic(e)
}
return string(bits)
}
import (
"io/ioutil"
)
func FileToString(filepath string) string {
bits, e := ioutil.ReadFile(filepath)
if e != nil {
panic(e)
}
return string(bits)
}
Check if a File Exists
package golang
import (
"os"
)
func FileExists(filepath string) bool {
_, e := os.Stat(filepath)
return e == nil
}
import (
"os"
)
func FileExists(filepath string) bool {
_, e := os.Stat(filepath)
return e == nil
}