首页 > 解决方案 > 写入网络映射驱动器 - 空文件或失败

问题描述

很抱歉通过关注真正的问题来重新格式化我的问题,如下所示:我正在尝试在网络映射驱动器上创建文件并写入它,我可以使用 Windows 资源管理器或 CMD 访问、创建、删除和编辑文件(Windows 10/服务器 2016)。

以下代码应该完成任务:

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)
}

该文件已成功创建,但是,使用的任何方法都没有写入它。Bufio.WriteString 既不写入也不返回错误!Fprintf 失败,错误消息不清楚,我搜索了该消息,但找不到含义或原因。

这是我在运行编译文件时得到的输出:

Error Flushing the write to file write H:/00_SC/Dest01.txt: The parameter is incorrect.
Error of Write call write H:/00_SC/Dest01.txt: The parameter is incorrect.
Length of mystring =  17
Bytes writen to buffer =  17
Fprintf Error:  write H:/00_SC/Dest01.txt: The parameter is incorrect.
Bytes written to file by Fprintf =  0
Bytes written to file using Write 0

感谢您的帮助和指导,以找出导致此错误的原因。谢谢

标签: windowsgocifs

解决方案


推荐阅读