摘要:
f, err := os.Open("test.txt") if err != nil { panic(err) } defer f.Close() rd := bufio.NewReader(f) for { line, err := rd.ReadString('\n') //以'\n'为结束符读入一行 if err != nil || io.EOF == err { break } fmt.Println(line) ... 阅读全文
摘要:
c := make(chan int) // Allocate a channel.// Start the sort in a goroutine; when it completes, signal on the channel.go func() { list.Sort() c <- 1 // Send a signal; value does not matter.}()doSomethingForAWhile()<-c // Wait for sort to finish; discard sent value.Receivers always block unt... 阅读全文