问题
I'm going to process CSV files using Apache Camel. My files have multiple header lines. In Camel I only find skipFirstLine or skipHeaderRecord (which is not clear for me) but how to skip more than one line?
回答1:
If the number of lines to skip is fixed, then you can use the simple language to skip X number. You likely need to covert the message to a String first,
.convertBodyTo(String.class)
.transform(simple("${skip(3)}")
See more about skip method at: http://camel.apache.org/simple
This requires Camel 2.19 onwards.
Using older releases you would need to build some custom code yourself to skip the lines.
回答2:
You can use tokenize
method on your body before processing the body.
tokenize(String token, int group, boolean skipFirst)
Example:
`from("filePath").
split(body().tokenize("\n",1,true)).
streaming().
process(exchange -> {....}).
to("filePath");`
来源:https://stackoverflow.com/questions/43520162/camel-how-to-skip-multiple-header-lines-in-csv-files