Apache Camel:如何对一个目录中的文件进行简单修改,然后将输出存储在另一个目录中?

Pau*_*ulP 0 routes file apache-camel

看似简单,但我不能让它工作.我想要做的是获取放置在"from"路径中的任何文件,修改其内容,并将修改后的文件放在"to"路径中(扩展名为.txt).这就是我所拥有的:

this.context.addRoutes(new RouteBuilder() {
    public void configure() {
        from( "file:" + getFromPath() + getOptions() )
        .to( "file:" + getToPath() + "?fileName=${file:name.noext}.txt")
        .process(new Processor() {
            public void process(Exchange exchange) throws Exception {
                String name = (String) exchange.getIn().getHeader("CamelFileName");
                File body = exchange.getIn().getBody(File.class);
                String parsedText = modifyFile(body);
                exchange.getOut().setBody(parsedText);
            }
         })
     ;}
  });
Run Code Online (Sandbox Code Playgroud)

输出文件正在创建,但内容与输入文件完全相同.即,文件未被修改.我确认"modifyFile"方法正在返回我想要的内容,但无法将它们写入输出("to")路径.

谢谢您的帮助!

Wil*_*ang 6

如果要修改文件内容,则需要将处理器放在"from"和"to"端点之间.

  • 是的它应该是:from - > process - > to (2认同)