repo.or.cz
/
go-om-arch-dev.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
blame
|
history
|
raw
|
HEAD
tcp实现乞丐版FTP
[go-om-arch-dev.git]
/
ch08
/
readfile-os-open
/
main.go
blob
1ae1323755022529a0b196fdc73d79e9d92ec226
1
package
main
2
3
import
(
4
"fmt"
5
"io"
6
"log"
7
"os"
8
)
9
10
func
main
() {
11
path
:=
"main.go"
12
file
,
err
:=
os
.
Open
(
path
)
13
if
err
!=
nil
{
14
log
.
Fatal
(
err
)
15
}
16
defer
file
.
Close
()
17
18
buf
:=
make
([]
byte
,
10
)
19
for
{
20
n
,
err
:=
file
.
Read
(
buf
)
21
if
err
!=
nil
{
22
if
err
!=
io
.
EOF
{
23
log
.
Println
(
"读取错误:"
,
err
)
24
}
25
break
26
}
27
fmt
.
Print
(
string
(
buf
[:
n
]))
28
}
29
}