Java 中的 CSV 解析 - 工作示例..? [英] CSV parsing in Java - working example..?
问题描述
我想为一个学校 java 项目编写一个程序来解析一些我不知道的 CSV.我知道每列的数据类型 - 尽管我不知道分隔符.
I want to write a program for a school java project to parse some CSV I do not know. I do know the datatype of each column - although I do not know the delimiter.
我什至不知道如何解决的问题是解析日期甚至日期时间列.它们可以是多种格式中的一种.
The problem I do not even marginally know how to fix is to parse Date or even DateTime Columns. They can be in one of many formats.
我找到了很多图书馆,但不知道哪个最适合我的需求:http://opencsv.sourceforge.net/http://www.csvreader.com/java_csv.phphttp://supercsv.sourceforge.net/http://flatpack.sourceforge.net/
I found many libraries but have no clue which is the best for my needs: http://opencsv.sourceforge.net/ http://www.csvreader.com/java_csv.php http://supercsv.sourceforge.net/ http://flatpack.sourceforge.net/
问题是我是一个完全的 Java 初学者.恐怕这些图书馆都不能做我需要的,或者我无法说服他们去做.
The problem is I am a total java beginner. I am afraid non of those libraries can do what I need or I can't convince them to do it.
我敢打赌,这里有很多人拥有代码示例,可以让我立即开始使用所需的代码:
I bet there are a lot of people here who have code sample that could get me started in no time for what I need:
- 在列中自动拆分(分隔符未知,列类型已知)
- 转换为 Columntype(应处理 $、% 等)
- 将日期转换为 Java 日期或日历对象
通过电子邮件获得尽可能多的代码示例会很好.
It would be nice to get as many code samples as possible by email.
非常感谢!AS
推荐答案
您还有 Apache Commons CSV 库,也许它可以满足您的需求.请参阅指南.2014-11 更新至 1.1 版.
You also have the Apache Commons CSV library, maybe it does what you need. See the guide. Updated to Release 1.1 in 2014-11.
此外,对于万无一失的版本,我认为您需要自己编写代码...通过 SimpleDateFormat
你可以选择你的格式,并指定各种类型,如果 Date
不像任何您预先想到的类型,它不是日期.
Also, for the foolproof edition, I think you'll need to code it yourself...through SimpleDateFormat
you can choose your formats, and specify various types, if the Date
isn't like any of your pre-thought types, it isn't a Date.
这篇关于Java 中的 CSV 解析 - 工作示例..?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!