I'm trying to use the file outbound channel adapter to write to dynamic directories based on message payload. For testing, I've configured the outbound channel adapter to use a base directory of "c:/temp", and am enriching the message with a header of FileHeaders.FILENAME of "2008-04-23/test.txt". It seems that FileWritingMessageHandler doesn't support creating parent directories of a file if it doesn't already exist, so a FileNotFoundException is thrown.

To work around this, I added a service activator before the outbound file adapter that creates the parent directory in case it doesn't exist:

Code:
  public Message<?> createParentDirectoriesIfNecessary(Message<?> message)
  {
    Assert.hasText(message.getHeaders().get(FileHeaders.FILENAME, "FileName header must exist!");
    File file = new File(rootDir, (String)message.getHeaders().get(FileHeaders.FILENAME);

    //create parent dirs if they don't exist
    if (file.getParentFile() != null && !file.getParentFile().exists())
    {
      file.getParentFile().mkdirs();
    }
    return message;
  }
I think it'd be a nice enhancement to handle these situations within the FileWritingMessageHandler, allowing for such configuration through the XML namespace.