Home  >  Article  >  Backend Development  >  How to determine whether a file can be written in Golang

How to determine whether a file can be written in Golang

尚
Original
2020-03-14 15:46:022150browse

How to determine whether a file can be written in Golang

Golang’s method of judging whether a file can be written:

The judgment code is as follows:

err := syscall.Access(file, syscall.O_RDWR)
if err != nil {
    fmt.Println(err.Error())
} else {
    fmt.Println("access ok")
}

Only syscall.Access needs to pass in the file and permission code, that is, whether it is allowed or not.

For more golang knowledge, please pay attention to the golang tutorial column on the PHP Chinese website.

The above is the detailed content of How to determine whether a file can be written in Golang. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn