This is a creation in Article, where the information may have evolved or changed.
Several function methods
| Name |
Role |
Note |
| ReadAll |
Reads the data, returns the read byte slice |
1 |
| ReadDir |
Reads a directory and returns an array of directory entries []os. FileInfo, |
2 |
| ReadFile |
Reads a file, returns the contents of the file (byte slice) |
3 |
| WriteFile |
Write bytes Slice According to the file path |
4 |
| TempDir |
Creates a temporary directory with the specified prefix name in a directory, returning the path to the new temporary directory |
5 |
| Tempfile |
Creates a temporary file of the specified prefix name in a directory, returning to the OS. File |
6 |
Example
ReadAll
func ReadAll(r io.Reader) ([]byte, error)
r := strings.NewReader("Go is a general-purpose language designed with systems programming in mind.")b, err := ioutil.ReadAll(r)if err != nil { log.Fatal(err)}fmt.Printf("%s", b)/*output:Go is a general-purpose language designed with systems programming in mind.*/
ReadDir
func ReadDir(dirname string) ([]os.FileInfo, error)
files, err := ioutil.ReadDir(".")if err != nil { log.Fatal(err)}for _, file := range files { fmt.Println(file.Name())}
WriteFile
func WriteFile(filename string, data []byte, perm os.FileMode) error