How to access images from a resource folder in intelliJ IDEA without having to give entire path name

26,167

You should use Java resource loading system. This is not depending on your IDE. Once you have marked a folder as resource folder in IntelliJ, it is available in your code as via resource loader.

Share:
26,167
Hobbs2000
Author by

Hobbs2000

Updated on July 09, 2022

Comments

  • Hobbs2000
    Hobbs2000 almost 2 years

    How would I do something like this in intelliJ IDEA

    File file = new File("C:\Users\Account\Documents\ProjectFolder\ResourceFolder\image");
    

    But not have to enter the whole file path in. I'm pretty sure there is a way, and I'm fairly certain it has something to do with adding it to my build path. I know how to do that in Eclipse but not in intelliJ.
    Thanks in advance!

  • Hobbs2000
    Hobbs2000 over 8 years
    Thanks for the help! I did end up using the resource loader, but I had to convert the java.net.URL it returned into a URI because the URL contained characters such as "%20". And those characters could not be used in the path for a new File. The new URI simply converted those characters into what they really mean, "%20" for instance is actually a space.