Java how to read folder and list files in that folder in jar environment instead of IDE

后端 未结 3 594
被撕碎了的回忆
被撕碎了的回忆 2021-02-09 05:29

my problem is that I create a folder(name is IconResources) under src , in IconResources there are many pictures. Directory is like this:

  • ProjectName
    • src
3条回答
  •  -上瘾入骨i
    2021-02-09 06:12

    Finally I work it out. I adopt Boris the Spider's answer, and it works well in IDE but break down in exported Jar. Then I change

    final InputStream is = loader.getResourceAsStream("text");

    to

    final InputStream is = loader.getResourceAsStream("./text");

    Then it works both in IDE and JAR.

提交回复
热议问题