golang报错:

parse error on line 1, column 4: bare " in non-quoted-field

可能的原因是csv是windowns 导出的,编码方式是UTF-8 BOM 方式。
可以通过跳过BOM解决:

import ("os""log"
)func main() {fd, err := os.Open("filename")if err != nil {log.Fatal(err)}defer closeOrDie(fd)bom := [3]byte_, err = io.ReadFull(fd, bom[:])if err != nil {log.Fatal(err)}if bom[0] != 0xef || bom[1] != 0xbb || bom[2] != 0xbf {_, err = fd.Seek(0, 0) // Not a BOM -- seek back to the beginningif err != nil {log.Fatal(err)}}// The next read operation on fd will read real data// ...
}

完成的例子:

package mainimport ("encoding/csv""io""log""monorepo/service/autotable/common/logger""os"
)func main() {fileName := "/mnt/result.csv"// 准备读取文件fs, err := os.OpenFile(fileName, os.O_RDWR|os.O_CREATE, os.ModePerm)if err != nil {logger.Log.Errorf("can not open the file, err is: %s", err)}defer fs.Close()bom := make([]byte, 3)_, err = io.ReadFull(fs, bom[:])if err != nil {log.Fatal(err)}if bom[0] != 0xef || bom[1] != 0xbb || bom[2] != 0xbf {_, err = fs.Seek(0, 0) // Not a BOM -- seek back to the beginningif err != nil {log.Fatal(err)}}content := make([][]string, 0)r := csv.NewReader(fs)//针对大文件,一行一行的读取文件for {row, err := r.Read()if err != nil && err != io.EOF {logger.Log.Infof("can not read, err is: %s", err)continue}if err == io.EOF {break}content = append(content, row)}logger.Log.Infof("len:%s", len(content))
}

parse error on line 1, column 4: bare “ in non-quoted-field相关推荐

  1. arse Error at line 58 column 17: The content of element type struts-config must match (display-na

    以前没有接触过struts1的项目  刚上来开发公司来的项目的时候遇到的这个错误. 报错信息: 严重: Parse Error at line 58 column 17: The content of ...

  2. Parse Fatal Error at line 4 column 43: 已经为元素 web-app 指定属性 xmlns。

    转载自:http://www.cnblogs.com/mophy/p/5987582.html Parse Fatal Error at line 4 column 43: 已经为元素 "w ...

  3. MongoDB解决“Error parsing YAML config file: yaml-cpp: error at line 2, column value(安装服务)

    解决"Error parsing YAML config file: yaml-cpp: error at line 2, column 13: illegal map value" ...

  4. Lexical error at line 1, column 18. Encountered: “\u2019“ (8217), after : ““]

    2020-12-04 09:58:20,184 ERROR [500.jsp] - nested exception is org.apache.ibatis.builder.BuilderExcep ...

  5. repomd.xml parser error:Parse error at line: 14 (xmlParseEntityRef: no name

    华为openEuler(EulerOS)系统 设置yum源 问题描述 在华为openEuler(EulerOS)系统上执行tar命令时候,提示找不到命令 tar: command not found ...

  6. Error on line 19, column 16 of pubspec.yaml: Mapping values are not allowed here. Did you miss a co

    错误如下图 这个错误的原因是自己导入引起的 看这个fluttertoast的位置对不上面的flutter位置没有对齐, 然后把他往前移动一下改成这样 上下对齐 这样的话 就可以了.

  7. Caused by: org.apache.ibatis.ognl.TokenMgrError: Lexical error at line 1, column 43. Encountered: <

    前言 报错 错误信息 [2020-12-15 13:56:33] -- [INFO ]: [com.xxxx.phb.exception.ExceptionHandlerAdvice]<

  8. octave错误-error: ‘squareThisNumber‘ undefined near line 1 column 1

    .m文件名称也应为大写:squareThisNumber.m 问题2: parse error near line 1 of file C:\Users\asus\squareThisNumber.m ...

  9. com.alibaba.fastjson.JSONException: syntax error, pos 1, line 1, column 2

    Controller承接HTTP请求,解析@RequestBody参数时,报错: HttpMessageNotReadableException: JSON parse error: syntax e ...

最新文章

  1. Ueditor和CKeditor 两款编辑器的使用与配置
  2. 李沐:五年工作反思!
  3. 北京公交线路查询(离线)
  4. FreeImage加速保存图像
  5. npm run dev 在本地调试出现跨域问题解决方法
  6. 【HDU - 2546】饭卡 (dp,0-1背包,贪心思想)
  7. 飞鸽传书完全不知道这是什么
  8. pyhon-matplotlib包-数据图形化
  9. python矩阵操作_Python中的矩阵操作
  10. 服务器biosraid管理
  11. python云计算服务_阿里云python 云计算
  12. Python爬虫编程实践 Task03
  13. python 自动回收机制
  14. 2016最新版App Store应用审核指南完整版
  15. 1.9 LaTex边注与脚注
  16. 贷款广告投放行为观察:价格高企主要客户是小贷公司,朋友圈转化效果最好
  17. 阿里网盘官网网页,怎么隐藏的这么深
  18. python读取tsv文件_Python读取tsv文件和evalu
  19. vs 2010 sp1 中文版 安装sliverlight 5 正式版
  20. 最全面的文本生成评价指标大盘点

热门文章

  1. 15.2,opencv绘制人脸识别框
  2. 【飞桨PaddleSpeech语音技术课程】— 语音唤醒
  3. 数据安全态势感知解决方案汇总
  4. 2019/8/18 ECU和DCU
  5. 【重磅】2021年SCI影响因子滚烫式公布!各领域TOP期刊!(附下载链接)
  6. 后台添加mp4 php,织梦后台编辑器增加MP4视频上传功能的方法
  7. 程序员如何实现财务自由?
  8. Ameya详解:村田的用于人机界面和生命体征检测的压电薄膜传感器
  9. word2vec损失函数
  10. 移动硬盘文件丢失如何找回丨500G硬盘