java csv 双引号_如何使用带有多个逗号和双引号的扫描器在java中读取.csv文件

有几种方式来实现你想要做什么,

1)使用现有的库,它支持解析CSV的像拉维Thapliyal和Oibaf它建议。

2)你可以提供你的方法

a). if every line in your CSV have a uniform format like :

line 1 : 123,student,"exam notif","word , word , word"

line 2 : 45345,not student,"no exam notif","word,word,word"

you can say like

while(scan.hasNextLine()){

String line = scan.nextLine();

//split it using double quotes first

temp = line.split("\"");

//then just remove commas outside the double quoted objects

for(int x = 0; x

if(temp[x].startsWith(",")) {temp[x] = temp[x].substring(1,temp[x].length()); }

if(temp[x].endsWith(",")) {temp[x] = temp[x].substring(0,temp[x].length()-1); }

}

至于这个程序员而言,Java没有任何现有的类,方法多的分隔符,但也有一些图书馆,可以使生活更轻松为你 ,但你总是有一个选择,提供自己的方法。 GUD运气

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值