如何使用可执行文件夹包含文本文件 [英] How to include text files with Executable Jar

查看:129
本文介绍了如何使用可执行文件夹包含文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨伙计们新手Java问题。



我有一个Java项目,我想在可执行jar中包含一个文本文件。现在,文本文件位于默认包中。



InputFlatFile currentFile = new InputFlatFile(src / theFile.txt);



我抓住文件您可以使用src看到该行。但是这不适用于可执行jar。



有人可以让我知道如何使用可执行jar保存此文件,这样使用该程序的人只需单击一个单个图标并运行程序。



谢谢!

解决方案

jar文件中的基目录位于类路径中。



尝试InputFlatFile currentFile = new InputFlatFile(theFile.txt);



您可能正在使用IDE它有一个src文件夹,IDE用于包的基础。当您从IDE创建jar文件时,它会删除src文件夹,并且根文件夹中包含包。



即。在eclipse src / com.blah.blah中创建jar文件后,结构变为com.blah.blah



当然我假设InputFlatFile正在正确读取值。 / p>

http://www.devdaily.com/blog/post/java/read-text-file-from-jar-file


Hi guys rookie Java question.

I have a Java project and I want to include a text file with the executable jar. Right now the text file is in the default package.

InputFlatFile currentFile = new InputFlatFile("src/theFile.txt");

I grab the file with that line as you can see using src. However this doesn't work with the executable jar.

Can someone please let me know how to keep this file with the executable jar so someone using the program can just click a single icon and run the program.

Thanks!

解决方案

The base directory in the jar file is in the classpath.

Try InputFlatFile currentFile = new InputFlatFile("theFile.txt");

You are probably using an IDE and it has a src folder in it that the IDE uses for the base of the packages. When you create the jar file from the IDE it then removes the src folder and the root folder has the packages in it.

i.e. in eclipse src/com.blah.blah once jar file is created the structure becomes com.blah.blah

Of course I assume that InputFlatFile is properly reading the value.

http://www.devdaily.com/blog/post/java/read-text-file-from-jar-file

这篇关于如何使用可执行文件夹包含文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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