当没有这样的文件返回 err 为 nil 时如何使用 os.Open

package main


import (

    "fmt"

    "os"

)


func main() {

    f := "D:\\cron"

    fmt.Println(os.Stat(f))

    fmt.Println(os.Open(f))


    f = "D:\\con"

    fmt.Println(os.Stat(f))

    fmt.Println(os.Open(f))

}


result:

<nil> CreateFile D:\cron: The system cannot find the file specified.

<nil> open D:\cron: The system cannot find the file specified.

<nil> CreateFile D:\con: The parameter is incorrect.

&{0xc000086a00} <nil>

我认为当文件不存在时,os.Open 应该返回 err != nil

但我想知道为什么“D:\con”返回 err == nil


叮当猫咪
浏览 99回答 1
1回答

陪伴而非守候

您使用 Windows 吗?“con”是保留文件名,是 DOS 时代的遗物。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go