C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Result: The program, once executed, will write several times to a file (you can change the path in the program).
Golang program that uses Fprint, Fprintf, Fprintln
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
// Create a file and use bufio.NewWriter.
f, _ := os.Create("C:\\programs\\file.txt")
w := bufio.NewWriter(f)
// Use Fprint to write things to the file.
// ... No trailing newline is inserted.
fmt.Fprint(w, "Hello")
fmt.Fprint(w, 123)
fmt.Fprint(w, "...")
// Use Fprintf to write formatted data to the file.
value1 := "cat"
value2 := 900
fmt.Fprintf(w, "%v %d...", value1, value2)
fmt.Fprintln(w, "DONE...")
// Done.
w.Flush()
}
Output
Hello123...cat 900...DONE...
However: For more advanced things, like using format strings, a func like Fprintf can lead to clearer code.