I have a JSON file called example.json. I need to read this file by taking its name as user input. I have tried with the below code.
func main() {
reader := bufio.NewReader(os.Stdin)
fmt.Print("Enter text: ")
text,_ := reader.ReadString('
')
fmt.Println(text)
file,_ := ioutil.ReadFile(text)
// os.Exit()
fmt.Print(file)
}
But It's not working properly. I want to take the JSON file name as a command line input and read the JSON file.
I checked with the below method. But it's not matched with my case.
reader.ReadString does not strip out the first occurrence of delim