本文介绍了如何在IntelliJ中将资源文件添加到JAR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在使用IntelliJ IDEA 14,我想将src外的文件添加到JAR文件中。这是我目前的项目结构。 我想将layout.txt和saveddata.txt添加到JAR文件可执行文件中。我一直在谷歌搜索一段时间找不到解决方案 如果你需要查看我的代码。这就是我读文件的方式 private Path layoutPath = Paths.get(resources / layout.txt); content = new String(Files.readAllBytes(layoutPath)); 这是我的项目结构 解决方案 在与src相同的级别创建一个名为resources的文件夹。 右键单击该文件夹,选择将目录标记为 - >资源根 I am using IntelliJ IDEA 14 and I want to add file outside of src to the JAR file. This is my current project structure.I want to add layout.txt and saveddata.txt to the JAR file executable. I've been googling on that for a while can't find the solutionIn case you need to see my code. This is how I am reading fileprivate Path layoutPath = Paths.get("resources/layout.txt");content = new String(Files.readAllBytes(layoutPath));Here is my project structure 解决方案Create a folder called "resources" at the same level as "src"Right click the folder, select "Mark Directory As -> Resources Root" 这篇关于如何在IntelliJ中将资源文件添加到JAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!