在JAVA中解析csv文件 [英] Parsing csv file in JAVA

查看:303
本文介绍了在JAVA中解析csv文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。



我用java解析csv文件并在jtable中存储,但我有一些问题。

当读取一行时,我存储字符串中的行,用逗号分隔。

csv文件有13列。现在,当最后一列是空的时,我的程序会因索引越界而崩溃(当其他列为空时这不是问题,只是当最后一列为空时出现问题)。



我试图将'\ 0'替换为'',但无济于事。



我需要帮助如何从上一栏读取空值。



谢谢,干杯


http://i.imgur.com/Ea2thLb.png[^]

Hi.

I'm parsing csv file with java and store in jtable, but i have some problem.
When read one row, I store the row in string and separate by comma.
The csv file have 13 columns. Now when the last column is empty my program crush with index out of bounds(this is not problem when some other column is empty, just problem when the last column is empty).

I've tried to replace '\0' with ' ', but won't help.

I need help how to read null value from last column.

Thanks, Cheers

http://i.imgur.com/Ea2thLb.png[^]

推荐答案

使用 http://docs.oracle.com/javase/1.5.0/docs/api /java/util/Scanner.html [ ^ ]。这允许您检查字符串中是否还有其他标记,这样您就可以知道最后一项是否为空。
Use http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Scanner.html[^]. This allows you to check whether there are any more tokens in the string, so you can know when the last item is null.


这篇关于在JAVA中解析csv文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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