tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
4
Task/Read-entire-file/Go/read-entire-file-1.go
Normal file
4
Task/Read-entire-file/Go/read-entire-file-1.go
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
import "io/ioutil"
|
||||
|
||||
data, err := ioutil.ReadFile(filename)
|
||||
sv := string(data)
|
||||
25
Task/Read-entire-file/Go/read-entire-file-2.go
Normal file
25
Task/Read-entire-file/Go/read-entire-file-2.go
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func main() {
|
||||
f, err := os.Open("file")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fi, err := f.Stat()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
data, err := syscall.Mmap(int(f.Fd()), 0, int(fi.Size()),
|
||||
syscall.PROT_READ, syscall.MAP_PRIVATE)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Println(string(data))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue