-
-
Save hyuki/35d431902b8b0d8e992506546ddafe2f to your computer and use it in GitHub Desktop.
os.Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"os" | |
"log" | |
) | |
func main() { | |
file, err := os.Open("sample.txt") | |
if err != nil { | |
log.Fatal(err) | |
} | |
data := make([]byte, 100) | |
count, err := file.Read(data) | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Printf("read %d bytes: %q\n", count, data[:count]) | |
err = file.Close() | |
if err != nil { | |
log.Fatal(err) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hello, world! | |
Hello, world! | |
Hello, world! | |
Hello, world! | |
Hello, world! | |
Hello, world! | |
Hello, world! | |
Hello, world! |
Author
hyuki
commented
Apr 9, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment