Package os provides a platform-independent interface to operating system functionality.
The os interface is intended to be uniform across all operating systems.
Features not generally available appear in the system-specific package syscall.
Constants
- O_RDONLY : read-only
- O_WRONLY : write-only
- O_RDWR : read-write
- O_APPEND : append data when writing
- O_CREATE : create if none exists
- O_EXCL : file must not exist
- O_SYNC : synchronous I/O
- O_TRUNC : truncate when opened
Variables
Args
Args hold the command-line arguments, starting with the program name.
var Args []string
Methods
Open
Open opens the named file for reading.
If successful, methods on the returned file can be used for reading; the associated file descriptor has mode O_RDONLY.
If there is an error, it will be of type *PathError.
func Open(name string) (*File, error)
Close
Close closes the FIle, rendering it unusable for I/O.
On files that support SetDeadline, any pending I/O operations will be canceled and return immediately with an error.
Close will return an error if it has already been called.
func (f *File) Close() error
Usages
file, err := os.Open("README.md")
if err != nil {
log.Fatal(err)
}
err = file.Close()
if err != nil {
log.Fatal(err)
}
'Go > Packages' 카테고리의 다른 글
[Go] Package fmt (0) | 2021.10.04 |
---|---|
[Go] Package testing (0) | 2020.11.30 |
[Go] Package log (0) | 2020.11.30 |
[Go] Package bufio (0) | 2020.10.31 |
[Go] Package errors (0) | 2020.10.29 |
댓글