FileNotFoundException after exporting as .jar file

后端 未结 2 788
粉色の甜心
粉色の甜心 2021-01-06 17:17

I\'m using Eclipse and developing a java application where I use of a local file. The file is inside the project folder, in a subfolder, say \"mydata/myfile.txt\" When I run

相关标签:
2条回答
  • 2021-01-06 17:45

    Maybe this will help you

    InputStream in=ClassLoader.getSystemResourceAsStream("your file");
    
    0 讨论(0)
  • 2021-01-06 17:48

    When your app is exported as a jar, your config file is not available as a file, since it's wrapped up in the .jar file. Instead you should access it via ClassLoader.getResourceAsStream(). See this SO question for more background info.

    0 讨论(0)
提交回复
热议问题