awesome-go/impl/files-manipulation/19-ReadAllBytesFromFile.go
2024-01-20 10:55:19 +02:00

32 lines
525 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"fmt"
"io"
"log"
"os"
)
func main() {
/*
Dosyanın Tüm Byte'ları Oku (Read All Bytes of File)
*/
// Okumak için dosya aç
file, err := os.Open("demo.txt")
if err != nil {
log.Fatal(err)
}
// os.File.Read(), io.ReadFull(), ioutil.ReadAll() ve io.ReadAtLeast() da kullanılabilir
data, err := io.ReadAll(file)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Data as hex: %x\n", data)
fmt.Printf("Data as string: &s\n", data)
fmt.Printf("Number of bytes read:", len(data))
}