java中的opencsv忽略字段值中的反斜杠 [英] opencsv in java ignores backslash in a field value

查看:273
本文介绍了java中的opencsv忽略字段值中的反斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用opencsv读取csv文件。

I am reading a csv file using opencsv.

我忽略了第一行; csv文件是制表符分隔的,其中一些值用双引号括起来。

I am ignoring the first line of; the csv file is tab separated with some values enclosed in double quotes.

当我读取具有'\'字符的列的值时会出现问题,这个被剥去了价值。

The problem occurs when I read the values of a column that has the '\' character, this is stripped out of the value.

reader = new CSVReader(new FileReader(exchFileObj),'\t','"',1);

例如在原始文件中:

address = 12\91buenosaires   

它成为:

address = 1291buenosiares

csvreader 生成的字符串数组中。如何修改它以便能够读取'\'字符?

In the string array that csvreader generates. How do I modify it to be able to read the '\' character also?

推荐答案

CSVReader还有构造函数,您可以通过它设置转义字符如果您使用它并将转义字符设置为您不使用的字符,您将在输入中得到反斜杠字符。

CSVReader also has a constructor via which you can set the escape character to use. If you use that and set the escape character to something you don't use you will get the backslash character in your input.

这篇关于java中的opencsv忽略字段值中的反斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆