```go
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))
}
结果如下:
<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()应该在文件不存在时返回错误,这样我就可以不多调一次os.Stat()
然而不知为啥会碰到上面这个问,搞不懂“D:\\con”这个为啥会是参数错误,而且os.Open竟然返回正常。
我明白你的意思了,我自己试了下确实是不可以使用con这个东西,会出现bug:
![image.png](https://static.studygolang.com/191017/fd66ce2b01c942f70993f539e1a9ae3d.png)
#19