2016-06-28 39 views
0

我有下面的代碼:如何檢查Apache Camel中是否存在文件?

package camelinaction; 

import org.apache.camel.CamelContext; 
import org.apache.camel.builder.RouteBuilder; 
import org.apache.camel.impl.DefaultCamelContext; 


public class MakeNotaBeneFile { 

    public static void main(String args[]) throws Exception { 
     // create CamelContext 
     CamelContext context = new DefaultCamelContext(); 

     // add our route to the CamelContext 
     context.addRoutes(new RouteBuilder() { 
      public void configure() { 
       from("quartz://report?cron=0/2+*+*+*+*+?") 
       .setBody().simple("\n") 
       .to("file:/c:/Users/Mishin/Documents/work_line/?fileName=${date:now:ddMMyyyy}/${date:now:ddMMyyyy}_nb.txt"); 
      } 
     }); 

     // start the route and let it do its work 
     context.start(); 
     Thread.sleep(1000); 

     // stop the CamelContext 
     context.stop(); 
    } 
} 

我有一個創建一個目錄,並用當前日期與駱駝 MakeNotaBeneFile.java

我的問題是,我怎麼能確認我的文件所在的文件中的代碼? 由於當前的代碼覆蓋舊文件,我丟失了筆記。

回答

2

請參閱camel file2 documentation中「生產者」選項下的駱駝文件組件的fileExist選項。

我相信像&fileExist=Append(或Fail)可能會幫助你。

另外看看,如果駱駝設法重新命名覆蓋的文件(文檔說駱駝2.11.1和以上有這種行爲)。

另外,如果你想在你的駱駝路線建立一個邏輯if,你總是可以建立一個bean含有一些像這樣的代碼:return new File(filename).exists();

+1

它與&fileExist =忽略,謝謝! –

相關問題