gpt4 book ai didi

java - 使用camel-bindy或beanio解析键值文本文件

转载 作者:行者123 更新时间:2023-12-01 13:59:24 35 4
gpt4 key购买 nike

我可以选择使用bindy 或beanIO Camel 组件来解析csv 文件。除了这个 csv 之外,还有包含键值的 dat (txt) 文件。是否可以使用提到的库之一将此文件解析为 Map?

最佳答案

bindy 组件可以将csv 文件解码为对象,而不是直接在 map 中。这是 related question 的响应克劳斯·易卜生。看来beanIO也是一样的。

但是,您可以使用 Camel 的 CSV 组件,它将您的文件转换为 List<List<String>> .

这是有关 bindy ( documentation on the Camel site ) 的更多信息。

您只需声明一个 DataFormat:

DataFormat bindy = new BindyCsvDataFormat("com.acme.model");

然后像这样使用它:

from("file://inbox")
.unmarshal(bindy)
.to("direct:whatYouWant");

参数"com.acme.model"对应于您定义模型的包。 Camel Bindy 提供了很多选项来配置绑定(bind),我鼓励您查看文档以获取更多详细信息,但基本模型如下所示:

@CsvRecord(separator = ",")
public class Order {

@DataField(pos = 1)
private int orderNr;

...
}

关于java - 使用camel-bindy或beanio解析键值文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19422273/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com