Fprintf 写入网络映射驱动器时出错
时间:2024-04-11
浏览:232
作者:佚名
今天golang学习网给大家带来了《Fprintf 写入网络映射驱动器时出错》,其中涉及到的知识点包括等等,无论你是小白还是老手,都适合看一看哦~有好的建议也欢迎大家在评论留言,若是看完有所收获,也希望大家能多多点赞支持呀!一起加油学习~
问题内容
我有以下代码段,它在本地驱动器上创建一个输出文件,并需要在网络映射驱动器上执行相同的操作,我们将其称为[h:]。 从命令行输入的文件名(完整路径名)作为参数[1]。
我使用的是 windows 10/server 2016
// the following will create and append to the file when required.
sourcefile, errf := os.openfile(os.args[1], s.o_create|os.o_append|os.o_rdwr, 0666)
if erro != nil {
panic(erro)
}
defer outfile.close()
我使用以下函数将地图写入此文件。
func map2linpro(inp map[string][]string, outfile io.writer) {
for k, v := range inp {
_, err := fmt.fprintf(outfile, "%s %s=%s %s\n", v[0], k, v[1], v[2])
if err != nil {
fmt.println("error writing to file: ", err)
}
}
}
如果输出文件位于本地驱动器上,则一切正常,但是当使用带有映射驱动器号的完整路径时,我收到以下错误:
error: write h://00_sc//dest01.txt: the parameter is incorrect.
我搜索了任何原因,但找不到。 如果有人提供帮助,我将不胜感激
以下是我在 openfile 之后添加 panic(erro) 后遇到的错误。 这证明错误源是fmt.fprintf
Error Writing to File: write H:/00_sc/dest01.txt: The parameter is incorrect.
谢谢大家。
解决方案
outfile, _ := os.openfile(os.args[2], os.o_create|os.o_append, 0666)
应该阅读
outfile, err := os.OpenFile(os.Args[2], os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
panic(err)
}
重写这些行,生成的错误消息应该给出原因的线索
终于介绍完啦!小伙伴们,这篇关于《Fprintf 写入网络映射驱动器时出错》的介绍应该让你收获多多了吧!欢迎大家收藏或分享给更多需要学习的朋友吧~golang学习网公众号也会发布Golang相关知识,快来关注吧!
本文内容来源于互联网,如有侵权请联系删除。
近期热门
11.18
11.15
站内热门
最新文章
热门专题
