I don't know syntax of Go. Can anybody help me to convert following java code in google's go language .
import java.io.*;
class FileWrite
{
public static void main(String args[])
{
try {
// Create file
FileWriter fstream = new FileWriter("out.txt");
BufferedWriter out = new BufferedWriter(fstream);
out.write("Hello Java");
// Close the output stream
out.close();
} catch (Exception e){ //Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
}
This java code creates a file named out.txt and write a string (Hello Java) on the file.
But, how this problem can solved ? play.golang.org/p/169zmQvK7m – alessandro
For example,
package main
import (
"fmt"
"os"
"strconv"
)
func routine(fd *os.File) {
abc := 1
fd.WriteString("Hello Go " + strconv.Itoa(abc) + " ok\n")
fd.WriteString("\nHello Gopher!\n")
}
func main() {
fd, err := os.Create("out.txt")
if err != nil {
fmt.Println(err)
return
}
defer fd.Close()
abc := 1
fd.WriteString("Hello Go " + strconv.Itoa(abc) + " ok\n")
fd.WriteString("\nHello Gopher!\n")
routine(fd)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With