在java中将两个csv文件合并为一个
我有两个 csv 文件,其中包含多个表中的多列。我正在使用 opencsv 来制作 csv 文件。 我想制作一个包含两个文件中所有列的 csv 文件。 这两个文件中有一个公共列。 但记录数并不相同。 请建议一些东西。任何帮助将不胜感激。
PS:连接两个文件只是意味着我想将所有列添加到一个文件中。这不是数据库连接。 我想要合并的 csv 文件并在某些工具中使用它来生成 pdf
I have two csv files with multiple columns from multiple tables.I am using opencsv to make csv files.
I want to make one csv file containing all the columns from both files.
There is one common column in both the files.
But number of records are not same.
Please suggest something. Any help would be appreciated.
P.S.: Joining two files simply mean i want to add all the columns in one file..It is not the database join .
I want the combined csv file and use it to in some tool to generate a pdf
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将一个文件加载到由公共列值作为键控的字典中,然后将第二个文件的所有记录附加到字典中的相应条目(同样通过公共列值)。
最后,将所有字典 k,v 对写入新文件。
即兴示例:
Load one file into a dictionary keyed by the common column value, then append all the records of the 2nd file to the respective entry in the dictionary (again by common column value).
Finally, write all dictionary k,v pairs to a new file.
improvised example:
如果我们知道哪些列有重复数据,我们可以这样做
We can do something like this if we know which columns have the duplicate data