How to determine whether a file can be written in Golang

Release: 2020-03-14 15:46:02
Original
2211 people have browsed it

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")
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!