Let's first create an empty 'sample.txt' file that we want to write upon. The example writes a string to a text file. The File.WriteString function writes the contents of a string to a file. Let's create a 'sample.txt' file and add the following content to it: My first fav programming languge is Go Lang By default, the function breaks the data into lines with line termination stripped. It reads data by tokens the Split function defines the token. The Scanner provides a convenient interface for reading data such as a file of newline-delimited lines of text. Output: G:\GoLang\examples>go run go_example.go Let's create a file named go_example.go and add the following content to it:Ĭontent, err := ioutil.ReadFile("sample.txt") My third fav programming languge is Python My second fav programming languge is Java My first fav programming languge is Go Lang Let's create a 'sample.txt' file and add the following content to it: The example reads the whole file and prints it to the console. This function is convenient but should not be used with very large files. The ioutil.ReafFile function reads the whole file into a string. Go - write to file with ioutil.WriteFile.Go - write to file with File.WriteString.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |