我不知道Go的語法。誰能幫助我將以下Java代碼轉換為Google的go語言。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()); } }}此Java代碼創(chuàng)建一個名為out.txt的文件,并在該文件上寫入一個字符串(Hello Java)。
3 回答

慕哥6287543
TA貢獻1831條經驗 獲得超10個贊
package main
import (
"fmt"
"os"
)
func main() {
fd, err := os.Create("out.txt")
if err != nil {
fmt.Println(os.Stderr, err)
return
}
// defer calls a function at the end of the current function.
defer fd.Close()
fd.WriteString("Hello Gopher!\n")
}
我希望這有幫助。如果不清楚,請指定需要解釋的部分。
- 3 回答
- 0 關注
- 450 瀏覽
添加回答
舉報
0/150
提交
取消