Extracting a file from the currently running JAR through code

前端 未结 3 1011
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-16 17:20

Are there any built-in methods I can use to allow users to extract a file from the currently running JAR and save it on their disk?

Thanks in advance.

3条回答
  •  执念已碎
    2020-12-16 18:07

    File file = new File("newname.ext");
    if (!file.exists()) {
         InputStream link = (getClass().getResourceAsStream("/path/resources/filename.ext"));
         Files.copy(link, file.getAbsoluteFile().toPath());
    }
    

提交回复
热议问题