【发布时间】:2015-04-23 20:07:36
【问题描述】:
我正在尝试使用 Camel 压缩文件夹。我有一个Processor,它创建了包含文件的文件夹:
public class CreateDirProcessor implements Processor {
public void process(Exchange exchange) throws Exception {
Message in = exchange.getIn();
File d = new File("myDir/hi");
d.mkdirs();
File f = new File(d, "hello.txt");
f.createNewFile();
in.setBody(f);
}
}
它工作正常。
在我的路线中,我尝试压缩 hi 文件夹,所以我这样做了:
public static void main(String[] args) throws Exception {
CamelContext context = new DefaultCamelContext();
ProducerTemplate template = context.createProducerTemplate();
context.addRoutes(new RouteBuilder() {
public void configure() {
from("direct:source")
.process(new CreateDirProcessor())
.marshal().zipFile().to("file:zipped");
}
});
context.start();
template.sendBody("direct:source", "test");
Thread.sleep(3000);
context.stop();
}
那是行不通的。我得到了:
TypeConversionException: Error during type conversion from type: java.io.File to the required type... `myDir/hi` is a directory
目录不是文件吗?不能用 Camel 压缩整个文件夹及其内容吗?
谢谢大家。
【问题讨论】:
标签: java apache-camel zipfile