12/17/2022 0 Comments Golang file peek![]() Let's first understand how the flag package works. Using the flag package, we can get the file path as input argument from the command line and then read its contents. Passing the file path as a command line flagĪnother way to solve this problem is to pass the file path as a command line argument. This seems to be an easy way but comes with the pitfall that the file should be located in the path specified in the program else this method will fail. The program will print the contents of test.txt Now the program can be run from any location and it will print the contents of test.txt.įor example, it will work even when I run it from my home directory cd ~/Documents/filehandling ![]() package mainĭata, err := ioutil.ReadFile("/home/naveen/Documents/filehandling/test.txt") Please change this path to the absolute location of your test.txt. I have modified the program and changed the path to an absolute one in line no. The simplest way to solve this problem is to pass the absolute file path.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |