很抱歉,我将重点放在实际问题上来重新格式化我的问题,如下所示: 我正在尝试创建文件并将其写入网络映射驱动器,我可以使用Windows资源管理器或CMD(Windows 10 / Server 2016)访问,创建,删除和编辑文件。
以下代码应完成任务:
Prelude> allCoords 3 4
[(0,0),(0,1),(0,2),(0,3),(1,0),(1,1),(1,2),(1,3),(2,0),(2,1),(2,2),(2,3)]
文件创建成功,但是,没有使用任何方法写入文件。 Bufio.WriteString既不写入也不返回错误! Fprintf失败,并显示了错误的错误消息,该消息我进行了搜索,无法找到含义或原因。
这是运行编译文件时得到的输出:
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
//The following is the file name on a network mapped drive H:
out, errc := os.OpenFile("H:/00_SC/Dest01.txt", os.O_CREATE|os.O_APPEND|os.O_RDWR, 0666)
if errc != nil {
fmt.Println("Error Creating/Wrting to Dest file :", errc)
}
defer out.Close()
wr := bufio.NewWriter(out)
mystring := "another line here"
d, err := wr.WriteString(mystring)
if err != nil {
fmt.Println("Error writing by Writer: ", err)
}
errflush := wr.Flush()
if errflush != nil {
fmt.Println("Error Flushing the write to file", errflush)
}
wrtd, errw := out.Write([]byte("Write something in the file"))
if errw != nil {
fmt.Println("Error of Writte call", errw)
}
fmt.Println("Length of mystring = ", len(mystring))
fmt.Println("Bytes written to buffer = ", d)
fd, errf := fmt.Fprintf(out, "Another line to the file using Fprintf %d", d)
if errf != nil {
fmt.Println("Fprintf Error: ", errf)
}
fmt.Println("Bytes written to file by Fprintf = ", fd)
fmt.Println("Bytes written to file using Write", wrtd)
}
感谢您的帮助和指导,以查找导致此错误的原因。 谢谢