os.Stdin | os.Stdout | os.Stderr
var (
Stdin = NewFile(uintptr(syscall.Stdin), /dev/stdin)
Stdout = NewFile(uintptr(syscall.Stdout), /dev/stdout)
Stderr = NewFile(uintptr(syscall.Stderr), /dev/stderr)
)
Stdin, Stdout, and Stderr are open Files pointing to the standard input, standard output, and standard error file descriptors.
Note that the Go runtime writes to standard error for panics and crashes; closing Stderr may cause those messages to go elsewhere, perhaps to a file opened later.
Stdin、Stdout和Stderr是打开的文件,指向标准输入、标准输出和标准错误文件描述符。
请注意,Go 运行时间会将恐慌和崩溃的信息写入标准错误;关闭 Stderr 可能会导致这些信息流向其他地方,可能是后来打开的文件。
./main < input.txt # 命令行可以通过管道符输入
os.Create
Create creates or truncates the named file. If the file already exists, it is truncated. If the file does not exist, it is created with mode 0666 (before umask). If successful, methods on the returned File can be used for I/O; the associated file descriptor has mode O_RDWR. If there is an error, it will be of type *PathError.
创建创建或截断命名的文件。如果该文件已经存在,它将被截断。如果文件不存在,将以0666模式(在umask之前)创建。如果成功,返回的文件上的方法可以用于I/O;相关的文件描述符具有O_RDWR模式。如果有一个错误,它将是*PathError类型的。
io.Copy
func Copy(dst Writer, src Reader) (written int64, err error)
Copy copies from src to dst until either EOF is reached on src or an error occurs. It returns the number of bytes copied and the first error encountered while copying, if any.
拷贝从src到dst,直到src上达到EOF或发生错误。它返回复制的字节数和复制时遇到的第一个错误(如果有)。
一个成功的Copy返回err == nil,而不是err == EOF。因为Copy被定义为从src读到EOF,所以它不把Read的EOF当作要报告的错误。
如果src实现了WriterTo接口,则通过调用src.WriteTo(dst)实现拷贝。否则,如果dst实现了ReaderFrom接口,那么就通过调用dst.ReadFrom(src)来实现拷贝。
io.MkdirAll
func MkdirAll(path string, perm FileMode) error
MkdirAll creates a directory named path, along with any necessary parents, and returns nil, or else returns an error. The permission bits perm (before umask) are used for all directories that MkdirAll creates. If path is already a directory, MkdirAll does nothing and returns nil.
MkdirAll创建一个名为path的目录,以及任何必要的父目录,并返回nil,否则返回一个错误。权限位perm(在umask之前)被用于MkdirAll创建的所有目录。如果path已经是一个目录,MkdirAll不做任何事情,并返回nil。
type FileInfo
type FileInfo = fs.FileInfo
A FileInfo describes a file and is returned by Stat and Lstat.
一个FileInfo描述了一个文件,并由Stat和Lstat返回。