写入网络映射的驱动器时出现Fprintf错误

写入网络映射的驱动器时出现Fprintf错误

本文介绍了写入网络映射的驱动器时出现Fprintf错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,它们在本地驱动器上创建一个输出文件,并且需要在网络映射的驱动器上做一个输出文件,我们称它为[H:].从命令行作为参数[1]输入的文件名(完整路径名).

I have the following piece of code which creates an output file on a local drive and required to do the same on a network mapped drive let's call it [H:].The file name (full path name) entered from command line as argument[1].

我正在使用Windows 10/Server 2016

I am using 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()

我使用以下功能将地图写入此文件.

I use the following function to write a map into this file.

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

如果输出文件位于本地驱动器上,则一切正常,但是当使用带有映射驱动器号的完整路径时,我收到以下错误消息:

Everything is working just fine if the output file is on the local Drive, but when using full path with the Mapped Drive letter, I received the following error:

Error:  write h://00_sc//dest01.txt: The parameter is incorrect.

我出于任何原因进行搜索,但找不到原因.如果有人帮忙,我将不胜感激

I searched for any reason, but could not find one.I would appreciate if someone help

以下是在OpenFile之后添加Panic(erro)后出现的错误.证明错误源是 fmt.Fprintf

The following is the Error I got after adding Panic(erro) after OpenFile.Which proves that the error source is 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)
}

重写这些行,并且产生的错误消息应提供有关原因的线索

rewrite those lines and the resulting error message should give a clue as to the cause

这篇关于写入网络映射的驱动器时出现Fprintf错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 23:22