java从jar文件复制目录
我最近开发了一个应用程序并创建了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);
}
不幸的是,这不起作用
我尝试了以下方法,但没有成功:
使用流解决类似问题 在其他课程上,但它不起作用 用dirs。代码与 http://www.exampledepot.com/egs/java.io/CopyFile.html
使用
new File(getClass().getResource("template").toUri())
写这篇文章的时候,我考虑的不是在资源路径中有一个模板目录,而是一个zip文件。通过这种方式,我可以将文件作为输入流,并在需要的地方解压。但我不确定这是不是正确的方法
共 (0) 个答案