我想问一个问题是否有将文件(即图像)复制到.jar文件的方法,因为我想部署一个程序,我创建了一个文件夹以及源代码(它们与源代码位于同一位置),文件夹在jar文件中(我使用 Netbeans 创建jar文件).....现在我想要的是我想将 JFileChooser 选择的文件复制到jar文件中的文件夹???? 任何想法都是衷心接受的.. !!!提前谢谢????
P.S .: 我已经尝试在网上搜索答案,但他们所知道的是如何将jar文件中的文件复制到另一个目录 ......
答案 0 :(得分:0)
JAR文件是ZIP压缩文件。
见S.O.回答可以将文件添加到现有ZIP存档的解决方案:Appending files to a zip file with Java
答案 1 :(得分:0)
假设您要将文件images / image1.gif添加到JAR文件中。
jar uf <fileName>.jar images/image1.gif
要更改目录,请使用-c
jar uf <fileName>.jar -C
在此命令中
jar uf jar-file input-file
在此命令中:
The u option indicates that you want to update an existing JAR file.
The f option indicates that the JAR file to update is specified on the command line.
jar-file is the existing JAR file that's to be updated.
input-file(s) is a space-delimited list of one or more files that you want to add to the Jar file.