[Go] OS - bufio readfile

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

type name struct {
	fname []byte
	lname []byte
}

func main() {
	fmt.Print("File path ")

	var filename string
	fmt.Scanln(&filename)

	file, _ := os.Open(filename)
	defer file.Close()

	names := make([]name, 0)

	s := bufio.NewScanner(file)
	for s.Scan() {
		s := strings.Split(s.Text(), " ")
		n := name{fname: []byte(s[0]), lname: []byte(s[1])}

		names = append(names, n)
	}

	for _, n := range names {
		fmt.Printf("first name: %s, last name: %s\n", n.fname, n.lname)
	}

}

 

posted @   Zhentiw  阅读(12)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2020-09-13 [React] Handle Recoil Asynchronous Selectors using Loadables in React
2020-09-13 [Docker] Create a Docker configuration for a NestJS API
2020-09-13 [Javascript] Joi for validation
2020-09-13 [Machine Learning] Unrolling Parameters
2019-09-13 [React] Add client-side validation to your React forms with Yup
2018-09-13 [TypeScript] Define Custom Type Guard Functions in TypeScript
2018-09-13 [Sqlite3] Sqlite Introduction
点击右上角即可分享
微信分享提示