我需要解析不规则(尽管一致)的“csv”文件。文件内容如下所示:
Field1: Field1Text
Field2: Field2Text
Field3 (need to ignore)
Field4 (need to ignore)
Field5
Field5Text
// Cars - for example
#,Col1,Col2,Col3,Col4,Col5,Col6
#1,Col1Text,Col2Text,Col3Text,Col4Text,Col5Text,Col6Text
#2,Col1Text,Col2Text,Col3Text,Col4Text,Col5Text,Col6Text
#3,Col1Text,Col2Text,Col3Text,Col4Text,Col5Text,Col6Text
理想情况下,我希望采用类似于这里的方法。
最终,我想要得到一个像这样的对象:
String field1;
String field2;
String field5;
List<Car> cars;
我目前有以下问题:
- 添加了一些探索性测试后,以#开头的行将被忽略。我不想这样,有没有办法进行转义?
- 我的意图是在汽车部分使用BeanListProcessor,并使用单独的行处理器处理其他字段。然后将结果合并到上述对象中。我是否漏掉了任何技巧?