Last active
February 6, 2017 12:19
-
-
Save s-hiiragi/94b0deeef00fcb3b9b6fc8a26d883462 to your computer and use it in GitHub Desktop.
GoでCSVファイルを読み込むサンプル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"os" | |
"io" | |
"encoding/csv" | |
) | |
func main() { | |
fp, err := os.Open("sample.csv") | |
if err != nil { | |
panic(err) | |
} | |
defer fp.Close() | |
reader := csv.NewReader(fp) | |
// reader.Comma = ',' // デフォルトではカンマが設定される | |
for { | |
record, err := reader.Read() | |
if err == io.EOF { | |
break | |
} else if err != nil { | |
panic(err) | |
} | |
fmt.Println(record) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hoge | fuga piyo | |
---|---|---|
foo | bar 2000 | |
fizz | <buzz, fizz buzz> | |
i | have a pen |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment