如何在 IntelliJ 中很好地组织和访问外部文件?
我正在使用 IntelliJ IDEA 进行编程。我正在编写一个游戏。该游戏需要将其数据保存在一些文件中(例如玩家数据、世界地图探索数据等)。当我想将我的开发环境与导出的 .jar 可执行文件分开时,就会出现问题。当引用我的项目中的文件时,我使用类似 "saves/world1/players/player1.data"
的路径。可使用 File("saves/world1/players/player1.data")
访问此文件。但是,我需要的文件越多,我的项目就越混乱,因为所有文件都添加到我的项目根目录中。另外,在导出 .jar 工件时,它仅导出 .jar 文件,我必须手动将所有其他文件复制到 .jar 文件所在的目录中。如何自动化这一过程以及如何更好地组织文件(例如将它们放在一个目录中以免弄乱我的项目根文件夹)?另外,我应该提到我使用 Kotlin,但我不认为这对于这个问题很重要。 Java 解决方案可能也同样有效。
I'm programming using IntelliJ IDEA. I'm programming a game. This game needs to save its data inside some files (for example player data, world map exploration data etc.). The problem arises when I want to separate my development environment from the exported .jar executable. When referring to a file in my project, I use a path like "saves/world1/players/player1.data"
. This file is accessible by using File("saves/world1/players/player1.data")
. However, the more files I need, the more my project gets cluttered, because all the files are added into my project root directory. Also, when exporting the .jar artifact, it only exports the .jar file and I have to copy all the other files manually into the same directory as the .jar file. How do I automate this process and how do I organize the files a little better (like putting them in one directory to not clutter my project root folder)? Also, I should mention that I use Kotlin, but I don't this it's important for this question. A Java solution might work just as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的应用程序是否在加载这些大型外部数据文件的地方声明文件路径属性。对于本地开发/测试,此默认值可以默认到您项目的本地路径,但是对于部署,您可能有启动或执行脚本,这些脚本允许用户配置位于.data'文件的位置。
Have you application declare a file path property from where you load these large external data files. For local dev/testing this can default to a path local to your project but for deployment you'd perhaps have start or execution scripts which allow the user to configure where there '.data' file located.