Reputation: 311
I have the next code:
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();
}
}
I have a code that creates a directory and a file with the current date with Camel MakeNotaBeneFile.java
My question is that how can I check if my file exists? Because current code overwrites the old file and I lost my notes.
Upvotes: 0
Views: 7493
Reputation: 40388
Please see the fileExist
option for the camel file component under "Producer" options in camel file2 documentation.
I believe something like &fileExist=Append
(or Fail
) might help you.
Also look if camel managed to rename the file that got overwritten (documentation says that camel 2.11.1 and up has this behaviour).
Alternatively if you wanted to build a logical if
in your camel route, you could always build a bean containing some code like this: return new File(filename).exists();
Upvotes: 2