잠시만 기다려 주세요

     '참사 일주일이 지났다.. 민주당은 눈치만 보며 아무것도 하지 않는다... 세월호 시즌2가 되어간다.. 뉴스가 사라지고 점점 잊혀지고 있다. 민주당의 방조 살인이 또 다시 시작되고 있다.'
전체검색 :  
이번주 로또 및 연금번호 발생!!   |  HOME   |  여기는?   |  바다물때표   |  알림 (19)  |  여러가지 팁 (1095)  |  추천 및 재미 (163)  |  자료실 (28)  |  
시사, 이슈, 칼럼, 평론, 비평 (799)  |  끄적거림 (142)  |  문예 창작 (719)  |  바람 따라 (75)  |  시나리오 (760)  |  드라마 대본 (248)  |  
살인!


    golang

golang - golang 파일 쓰기, file write, Writing Files
이 름 : 바다아이   |   조회수 : 10016         짧은 주소 : https://www.bada-ie.com/su/?661591819751
// Writing files in Go follows similar patterns to the
// ones we saw earlier for reading.

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"os"
)

func check(e error) {
	if e != nil {
		panic(e)
	}
}

func main() {

	// To start, here's how to dump a string (or just
	// bytes) into a file.
	d1 := []byte("hello\ngo\n")
	err := ioutil.WriteFile("dat1.txt", d1, 0644)
	check(err)

	// For more granular writes, open a file for writing.
	f, err := os.Create("dat2.txt")
	check(err)

	// It's idiomatic to defer a `Close` immediately
	// after opening a file.
	defer f.Close()

	// You can `Write` byte slices as you'd expect.
	d2 := []byte{115, 111, 109, 101, 10}
	n2, err := f.Write(d2)
	check(err)
	fmt.Printf("wrote %d bytes\n", n2)

	// A `WriteString` is also available.
	n3, err := f.WriteString("writes\n")
	fmt.Printf("wrote %d bytes\n", n3)

	// Issue a `Sync` to flush writes to stable storage.
	f.Sync()

	// `bufio` provides buffered writers in addition
	// to the buffered readers we saw earlier.
	w := bufio.NewWriter(f)
	n4, err := w.WriteString("buffered\n")
	fmt.Printf("wrote %d bytes\n", n4)

	// Use `Flush` to ensure all buffered operations have
	// been applied to the underlying writer.
	w.Flush()

}


결과

wrote 5 bytes
wrote 7 bytes
wrote 9 bytes

$ cat dat1.txt

hello
go

$ cat dat2.txt

some
writes
buffered


출처 : https://gobyexample.com/writing-files
| |





      1 page / 6 page
번 호 카테고리 제 목 이름 조회수
180 golang golang ... 바다아이 142
179 golang golang , ... 바다아이 2727
178 golang golang , map . 바다아이 2112
177 golang Golang (, , data ) , ... 바다아이 2439
176 golang golang sort ... 바다아이 2810
175 golang golang html.EscapeString html.UnescapeString input value ... 바다아이 2734
174 golang golang go.mod go.sum . GOPATH SRC not module, 1.16 . 바다아이 6262
173 golang go 1.16 ... is not in GOROOT.. GOPATH .... . 바다아이 7416
172 golang , String Formatting 바다아이 8718
171 golang rand.Intn , random, , . 바다아이 8260
170 golang golang ... 바다아이 12007
169 golang golang gopath, goroot .. golang 바다아이 8977
168 golang golang ... Force download file example 바다아이 11007
167 golang golang , , cpu, memory, disk 바다아이 12072
166 golang golang , ... GOOS, GOARCH 바다아이 9719
165 golang golang checkbox ... 바다아이 9596
164 golang golang , , http .... 바다아이 9412
163 golang golang nil , nil , nil ... 바다아이 9491
162 golang 2 golang, go , .... golang .... 바다아이 12737
161 golang golang postgresql, mysql, mariadb ... ` Grave () .. .. 바다아이 10051
160 golang golang postgresql mysql, mariadb scan , null .. 바다아이 10123
159 golang golang , iconv 바다아이 12938
158 golang golang quote escape, unquote 바다아이 10355
157 golang golang , http errorLog , , ... 바다아이 10744
156 golang golang interface , 바다아이 9811
155 golang golang struct .... 바다아이 10533
154 golang golang map map , 바다아이 10013
153 golang golang map .... .... 바다아이 9344
152 golang golang slice copy 바다아이 9534
151 golang golang goto 바다아이 10718
| |









Copyright ⓒ 2001.12. bada-ie.com. All rights reserved.
이 사이트는 리눅스에서 firefox 기준으로 작성되었습니다. 기타 브라우저에서는 다르게 보일 수 있습니다.
[ Ubuntu + GoLang + PostgreSQL + Mariadb ]
서버위치 : 오라클 클라우드 춘천  실행시간 : 0.29502
to webmaster... gogo sea. gogo sea.