V
V
Vadim Rublev2021-09-12 12:18:27
go
Vadim Rublev, 2021-09-12 12:18:27

Why are files opening unstable?

Why is one file opened and read, while the other is the same (located in the same folder) is not? The functions os.OpenFile("file.txt", os.O_RDWR, 0666) and ioutil.ReadFile("file.txt").
Is this a Go thing or are there nuances with the files themselves (attributes in Windows OS or something else)?
In the "Properties" of these files, everything is the same. In general, they are the same, created at the same time. OS Windows.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evgeny Mamonov, 2021-09-12
@Vadim Rublev

I suspect that os.OpenFile does not work, but ioutil.ReadFile does.
And most likely the matter is in the rights os.OpenFile("file.txt", os.O_RDWR, 0666).
Start by handling the error so that you can understand what exactly is wrong.

f, err := os.OpenFile("file.txt", os.O_RDWR, 0666)
if err != nil {
    log.Fatalln(err)
}

PS: ioutil.ReadFile("file.txt") calls the OpenFile(name, O_RDONLY, 0) function to open a file

V
Vadim Rublev, 2021-09-12
@VadimRublev

Maybe OpenFile() is superfluous here, I added it in an attempt to solve the problem (it was the same without it).
The error for both functions is the same (the file was found correctly):
613dd322d92dc679883221.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question