Working with files
One of the most common and primitive ways to communicate is through files. Even after the introduction of databases, the filesystem has not lost its relevance and we frequently need to deal with them—in legacy applications, for dumping reports, shared locations, and so on.
So, how do you work with files in Java? Get the file handle, open a stream, work over it, and then close it. Some trivial stuff would take 10-15 lines of code. However, what if you forget to close the stream or the referenced file has been removed? The lines of code go on increasing as we handle all the corner cases. Spring Integration has very good support for files. It provides adapters and gateways that can handle file reading and writing operations with minimal lines of code.
Prerequisites
To use the file components mentioned previously, we need to declare the Spring namespace support and Maven entry in the following way:
Namespace support can be added by using the following code snippet:
xmlns:int-file...