更改jar中的文件 [英] Change file in jar

查看:66
本文介绍了更改jar中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我有一个jar文件,在这个jar中还有另一个config.js文件,我想在这个文件中写.我有此文件的Resource类(org.springframework.core.io.Resource),因此我可以从此Resource获取完整的URL或getFile(). URL看起来像这样:

so, i have a jar file and in this jar there is another config.js file, and in this file i want to write. I have a Resource class of this file (org.springframework.core.io.Resource), so i can get a full URL or getFile() from this Resource. URL look's like this:

jar:file:/Users/admin/.m2/repository/code/1.1-SNAPSHOT/code-1.1-SNAPSHOT.jar!/META-INF/config.js

问题是,如果我尝试从Resource获取getFile(),则会得到异常:无法解析为绝对文件路径,因为它不驻留在文件系统中. 那么我如何在jar中写入此文件?:)

The porblem is, if i try to getFile() from Resource i get an Exception : cannot be resolved to absolute file path because it does not reside in the file system. So how can i write to this file in jar?:)

推荐答案

您可以使用 jar上的> ZipStreams ,然后从那里可以处理jar. 直接处理jar的最佳方法是使用 ZipFile 甚至更好的 JarFile

You can use ZipStreams on your jar, and from there you can handle your jar. The best way to handle your jar directly is to use ZipFile or even better JarFile

这篇关于更改jar中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆