Notice
Recent Posts
Recent Comments
Link
투케이2K
66. (Go Lang) [Mac Os] Go 문법 : os 모듈 - ReadFile 사용해 텍스트 파일 읽기 실시 - read text file 본문
Go Lang (Go 언어)
66. (Go Lang) [Mac Os] Go 문법 : os 모듈 - ReadFile 사용해 텍스트 파일 읽기 실시 - read text file
투케이2K 2024. 2. 23. 20:44[개발 환경 설정]
개발 언어 : Go

[사전) 프로젝트에 파일 추가 방법]


[소스 코드]
package main
import (
"fmt"
"os"
)
func main() {
// ---------------------------------------------------
// [기본 설명]
// ---------------------------------------------------
// "os" 패키지를 사용해 파일 읽기 및 쓰기를 수행할 수 있습니다
// ---------------------------------------------------
// ReadFile : 파일 읽기를 수행 시 사용합니다
// ---------------------------------------------------
file, err := os.ReadFile("test.txt")
if err != nil {
panic(err)
}
// [로그 출력]
fmt.Println("")
fmt.Println("----------------------------------------------")
fmt.Println("[로그 출력 수행]")
fmt.Println("----------------------------------------------")
fmt.Println(string(file))
fmt.Println("----------------------------------------------")
fmt.Println("")
}
[결과 출력]

반응형
'Go Lang (Go 언어)' 카테고리의 다른 글
Comments