Created
February 15, 2024 21:02
-
-
Save yakuter/154152f4e743bcac5f80e4a8ec4cb484 to your computer and use it in GitHub Desktop.
Copy and Movement 11
This file contains 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" | |
"io" | |
"strings" | |
) | |
func main() { | |
reader := strings.NewReader("This is a test message.") | |
buf := make([]byte, 8) | |
for { | |
n, err := reader.Read(buf) | |
if n > 0 { | |
fmt.Printf("Read data: %s\n", string(buf[:n])) | |
} | |
if err == io.EOF { | |
break // End of the file. Exit from loop. | |
} | |
if err != nil { | |
fmt.Println("Failed to read:", err) | |
return | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment