将 CSV 文件导入 Java

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9991128/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 23:09:47  来源:igfitidea点击:

Importing a CSV File into Java

javacsv

提问by Nick Welki

In the program I am writing, I want to be able to import CSV files. At the moment, it takes a basic text file in.

在我正在编写的程序中,我希望能够导入 CSV 文件。目前,它需要一个基本的文本文件。

File mainemails = new File ("mainemails.txt");

I know that for CSV imports using File is probably not the most time-efficient thing to use. What would be the most efficient way to import a CSV file? Would I have to download any new libraries to use an efficient method?

我知道使用 File 导入 CSV 可能不是最省时的方法。导入 CSV 文件的最有效方法是什么?我是否必须下载任何新库才能使用有效的方法?

回答by Jayan

You can use opencsvfor importing csv data and then constructing objects from it.

您可以使用opencsv导入 csv 数据,然后从中构建对象。

I prefer using libraries so that I can save development time. Also they tend to solve specific problems better.

我更喜欢使用库来节省开发时间。他们也倾向于更好地解决特定问题。

回答by darrengorman

Try OpenCSVas suggested hereand here.

按照此处此处的建议尝试OpenCSV