windows - 写入网络映射驱动器 - 空文件或失败
问题描述
很抱歉通过关注真正的问题来重新格式化我的问题,如下所示:我正在尝试在网络映射驱动器上创建文件并写入它,我可以使用 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
感谢您的帮助和指导,以找出导致此错误的原因。谢谢
解决方案
推荐阅读
- asp.net-core - .NET CORE 2.0 尝试激活时无法解析服务类型
- python - Selenium 加载时间错误 - 寻找可能的解决方法
- java - 如何将发件人的消息放在左侧,将收件人的消息放在右侧
- reactjs - 我正在尝试在 React js 中创建一个 onDimiss 按钮
- go - Kafka 消息未传递给消费者
- c# - Xamarin - 智能手机内存中的存储数据
- php - laravel 属于不使用一对一关系
- php - PHP preg_replace 用html替换通配符字符串以及通配符之后会发生什么
- node.js - 如何使用 Create-React-App 的节点服务器定义 MIME 类型?
- tensorflow - 如何在张量流中为我的网络提供正确的数组大小