How to access static resources in Java

Your Java app may need access to data that you intend to ship directly with your code and which will not change without a version update. Examples might include a list of countries to show in a country dropdown, or icon images for a web or Swing application. The proper mechanism to access these files is: YourClass.class.getResource("file.txt"); // or YourClass.class.getResourceAsStream("file.txt"); This mechanism is built into java and will...

6 minute(s) read