3
我想用骆驼压缩文件夹。我有一个Processor
,它创建了文件夹里面的文件:Apache骆驼zip文件夹
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
目录不是文件吗?是否无法用骆驼压缩整个文件夹及其内容?
谢谢大家。
谢谢,我会检查这个。 –