我最近开发了一个应用程序并创建了jar文件.
我的一个类创建了一个输出目录,用它的资源填充文件.
我的代码是这样的:
// Copy files from dir "template" in this class resource to output.
private void createOutput(File output) throws IOException {
File template = new File(FileHelper.URL2Path(getClass().getResource("template")));
FileHelper.copyDirectory(template, output);
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,这不起作用.
没有运气我尝试了以下内容:
使用Streams解决其他类的类似问题,但它不适用于dirs.代码类似于 http://www.exampledepot.com/egs/java.io/CopyFile.html
使用创建文件模板 new File(getClass().getResource("template").toUri())
在写这篇文章的时候,我正在思考而不是在资源路径中有一个模板目录,而是有一个zip文件.这样做我可以将文件作为inputStream并将其解压缩到我需要的位置.但我不确定这是不是正确的方法.