1.Camel-File Transfer Example

This is the post excerpt.

File-based information exchange is common between distributed system. For example, A java application getting data from the legacy system in txt files and application read those txt files from inbox directory and after receiving a file in inbox directory file moved to outbox directory after processing.

In the following example, we will learn how to route a file from one directory to another directory.

For example .. emplyoyee.txt file is present in inbox directory and application will move it to the outbox directory.
employee.txt file content is

package com.kp.work.camel;

import org.apache.camel.builder.RouteBuilder;

public class EmployeeFileRouter extends RouteBuilder {

 public void configure() throws Exception {

If you want to keep the original file as is in inbox directory we need to set the noop option to true.
Try this example with option noop =false to differentiate the behavior.

If you want to give different filename use fileName option to set different file name.
Here is the modified configure method with fileName option.
File name changed from employee.txt to empdetails.txt

 public void configure() throws Exception {

By default camel moves file to .camel directory.If you want to move file to different directory you can use move option.Moving file to different directory is good option after processing because you can avoid processing same file over and over and you can also keep the backup of processed files.

Modified configure method with move option.

 public void configure() throws Exception {

package com.kp.work.camel;

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

public class EmployeeMain {

	public static void main(String[] args) {
		CamelContext camelContext = new DefaultCamelContext();
		try {
			camelContext.addRoutes(new EmployeeFileRouter());
		} catch (Exception e) {


In order to run this example we need camel-core dependency because file component is present in camel-core jar

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s