fileio

package
v0.0.30 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultCSVFileName = fmt.Sprintf("writer-%d.csv", times.NowMilli())

Functions

This section is empty.

Types

type CSVFileIO

type CSVFileIO struct {
	File     *os.File
	Writer   *csv.Writer
	Reader   *csv.Reader
	Filename string
}

CSVFileIO CSV文件读写器结构体

func NewCSVFileIO

func NewCSVFileIO(pathAndName string) *CSVFileIO

NewCSVFileIO 创建一个新的CSV写入器实例 pathAndName: CSV文件路径 eg: ./path/to/filename.csv 返回CSVWriter指针

func (*CSVFileIO) Close

func (w *CSVFileIO) Close() error

Close 关闭CSV文件并刷新缓冲区

func (*CSVFileIO) Create

func (w *CSVFileIO) Create(headers []string) error

Create 创建CSV文件并可选择写入表头(读模式) headers: 可选的表头行数据

func (*CSVFileIO) Open

func (w *CSVFileIO) Open() error

Open 打开已存在的CSV文件用于读取(写模式)

func (*CSVFileIO) ReadAll

func (w *CSVFileIO) ReadAll() ([][]string, error)

ReadAll 读取CSV文件的所有数据 返回二维字符串切片包含所有行数据

func (*CSVFileIO) Write

func (w *CSVFileIO) Write(values []string) error

Write 向CSV文件写入一行数据 values: 要写入的字符串切片

type Files

type Files interface {
	Create(headers []string) error
	Open() error
	Write(values []string) error
	ReadAll() ([][]string, error)
	Close() error
}

Files 定义文件读写接口

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL