I am relatively new to java programming. I want to know how we can add external files to our .jar. for e.g. i want to add a .tx
t file to my .jar
so that when someone runs my program, it can ask user where it wants to store that .txt
and then copy it at that location. Is it possible to do so? So far all i have been able to find is Open external file with an external program.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
JAR files can contain any kind of file. For example JEE uses war files and ear files, these are really just extended jar files and contain various XML files in addition to the java.
You can read files from a JAR by using methods of any class
MyClass.class.getResource("/path/to/myfile.txt")
回答2:
yes you can do this if you want.. By running this command
**jar uf jar-file input-file(s)**
http://docs.oracle.com/javase/tutorial/deployment/jar/update.html