-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy path06-OpenCloseFile.go
More file actions
45 lines (35 loc) · 951 Bytes
/
06-OpenCloseFile.go
File metadata and controls
45 lines (35 loc) · 951 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"log"
"os"
)
func main() {
/*
Dosyaları Açma ve Kapama (Open and Close Files)
*/
// Dosyayı salt okunur olarak açtık
file, err := os.Open("demo.txt")
if err != nil {
log.Fatal(err)
}
file.Close()
// OpenFile çok seçenekli dosya açma yöntemidir.
// İkinci parametre dosya açılış amacını ayarlarken, üçüncü parametre dosya izinlerini belirler.
file, err = os.OpenFile("demo.txt", os.O_APPEND, 0666)
if err != nil {
log.Fatal(err)
}
file.Close()
/*
OpenFile() ikinci parametrenin tipleri;
os.O_RDONLY : Sadece okuma
os.O_WRONLY : Sadece yazma
os.O_RDWR : Okuma ve yazma yapılabilir
os.O_APPEND : Dosyanın sonuna ekle
os.O_CREATE : Dosya yoksa oluştur
os.O_TRUNC : Açılırken dosyayı kes
Bu ayarlar birden fazla olarak da kullanılabilir
-> os.O_CREATE|os.O_APPEND
-> os.O_CREATE|os.O_TRUNC|os.O_WRONLY
*/
}