How to move files using ExpressionEvaluatingRequestHandlerAdvice

烂漫一生 提交于 2019-12-02 10:12:42

If the new directory is on the same disk as the old one, in the 'onSuccessExpression', simply use payload.renameTo(...) similar to the way the sample does in the onFailureExpression.

`payload.renameTo(new java.io.File(new File('newDir'), payload.name))`

Creates a file with the payload's name to a directory newDir (which must exist).

If you are JDK 7 or above use...

T(java.nio.file.Files).move(payload.path, new java.io.File(new File('newDir'), payload.name).path)

...instead.

This will handle the situation of the new directory being on a different disk (which a simple File.renameTo() will not).

If you are still on JDK 6 and the new directory might be on a different disk you will need to use onSuccessExpression=payload and subscribe a service activator to the successChannel to manipulate the file itself, perhaps using Spring's FileCopyUtils.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!