将外部文件添加到jar [英] Add external files to jar

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

问题描述

我对java编程比较陌生。我想知道如何将外部文件添加到.jar中。例如我想将 .tx t文件添加到我的 .jar ,这样当有人运行我的程序时,它可以询问用户想要存储 .txt 然后在该位置复制它。有可能这样做吗?到目前为止,我所能找到的是使用外部程序打开外部文件

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 .txt 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.

推荐答案

JAR文件可以包含任何类型的文件。例如,JEE使用war文件和ear文件,这些文件实际上只是扩展的jar文件,除了java之外还包含各种XML文件。

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.

您可以从JAR读取文件通过使用任何类的方法

You can read files from a JAR by using methods of any class

 MyClass.class.getResource("/path/to/myfile.txt")

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

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