Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 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)
|
||||
27
Task/Read-entire-file/Go/read-entire-file-2.go
Normal file
27
Task/Read-entire-file/Go/read-entire-file-2.go
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
// +build !windows,!plan9,!nacl // These lack syscall.Mmap
|
||||
|
||||
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