Недавно я разработал приложение и создал файл 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);
}
К сожалению, это не работает.
Я попробовал следующее без везения:
-
Использование Streams для решения подобных задач на других классах, но он не работает с каталогами. Код был похож на http://www.exampledepot.com/egs/java.io/CopyFile.html
-
Создание шаблона файла с помощью
new File(getClass().getResource("template").toUri())
Во время написания этого я думал, вместо того, чтобы иметь шаблон dir в пути ресурса, имеющий его zip файл. Сделав это таким образом, я мог бы получить файл как inputStream и разархивировать его там, где мне нужно. Но я не уверен, правильно ли это.