os.ReadFile reads an entire file from disk and returns its contents as a byte slice, or an error when reading fails. Because files are bytes rather than lines, callers must convert and parse the result for their use case. section 5.3.2
A typical text-file workflow is:
- Call os.ReadFile with the file path and propagate failures, commonly by wrapping the returned error with fmt.Errorf and %w. section 5.3.2 section 5.6
- Convert text bytes to a string and use strings.Fields when whitespace-separated words are required. section 5.3.2
Reading a word corpus
A corpus loader calls data, err := os.ReadFile(path), wraps a read failure with the path, rejects empty data with a sentinel error, and returns strings.Fields(string(data)) as the word list.
func ReadFile(name string) ([]byte, error)
Signature: func ReadFile(name string) ([]byte, error). section 5.3.2

