parse error on line 1, column 4: bare “ in non-quoted-field
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相关推荐
- 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 ...
- 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 ...
- 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" ...
- 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 ...
- repomd.xml parser error:Parse error at line: 14 (xmlParseEntityRef: no name
华为openEuler(EulerOS)系统 设置yum源 问题描述 在华为openEuler(EulerOS)系统上执行tar命令时候,提示找不到命令 tar: command not found ...
- Error on line 19, column 16 of pubspec.yaml: Mapping values are not allowed here. Did you miss a co
错误如下图 这个错误的原因是自己导入引起的 看这个fluttertoast的位置对不上面的flutter位置没有对齐, 然后把他往前移动一下改成这样 上下对齐 这样的话 就可以了.
- 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]<
- 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 ...
- com.alibaba.fastjson.JSONException: syntax error, pos 1, line 1, column 2
Controller承接HTTP请求,解析@RequestBody参数时,报错: HttpMessageNotReadableException: JSON parse error: syntax e ...
最新文章
- Ueditor和CKeditor 两款编辑器的使用与配置
- 李沐:五年工作反思!
- 北京公交线路查询(离线)
- FreeImage加速保存图像
- npm run dev 在本地调试出现跨域问题解决方法
- 【HDU - 2546】饭卡 (dp,0-1背包,贪心思想)
- 飞鸽传书完全不知道这是什么
- pyhon-matplotlib包-数据图形化
- python矩阵操作_Python中的矩阵操作
- 服务器biosraid管理
- python云计算服务_阿里云python 云计算
- Python爬虫编程实践 Task03
- python 自动回收机制
- 2016最新版App Store应用审核指南完整版
- 1.9 LaTex边注与脚注
- 贷款广告投放行为观察:价格高企主要客户是小贷公司,朋友圈转化效果最好
- 阿里网盘官网网页,怎么隐藏的这么深
- python读取tsv文件_Python读取tsv文件和evalu
- vs 2010 sp1 中文版 安装sliverlight 5 正式版
- 最全面的文本生成评价指标大盘点