Class ResourceUtil


  • public class ResourceUtil
    extends Object
    ResourceUtil is a utility class for retrieving resources (images, property-files, etc) from the classpath.
    • Constructor Detail

      • ResourceUtil

        public ResourceUtil()
    • Method Detail

      • getURL

        public static URL getURL​(String resourceName)
        The URL to the specified resource
        Parameters:
        resourceName - the name of the resource
        Returns:
        the URL to the specified resource, or null if the resource could not be found
      • getInputStream

        public static InputStream getInputStream​(String resourceName)
        Get an inputstream on the specified resource.
        Parameters:
        resourceName - the name of the resource
        Returns:
        an inputstream on the specified resource, or null if the resource could not be found
      • getString

        public static String getString​(String resourceName)
                                throws IOException
        Retrieve the String contents of the specified resource, obtained by opening in inputstream on the resource and then interpreting the bytes contained in the inputstream as if they represented characters. This may not make sense on all resources. There is no "magic" in this method to read anything other than plain text.
        Parameters:
        resourceName - the name of the resource
        Returns:
        the String contents of the specified resource, or null if the specified resource could not be found
        Throws:
        IOException - when something goes wrong trying to read the resource
      • getProperties

        public static Properties getProperties​(String resourceName)
                                        throws IOException
        Retrieve a properties resource.
        Parameters:
        resourceName - the name of the resource
        Returns:
        a Properties object representing the contents of the resource, or null if the specified resource could not be found
        Throws:
        IOException