List of utility methods to do Resource Get
byte[] | getResourceAsBytes(String resource) Gets the resource as bytes. ClassLoader cl = Thread.currentThread().getContextClassLoader();
URL url = cl.getResource(resource);
InputStream is = url.openStream();
return getStreamContentAsBytes(is);
|
File | getResourceAsFile(Class clazz, String resource) Gets a resource relative to the given class. return new File(clazz.getResource(resource).getFile()); |
File | getResourceAsFile(Class klass, String resource) Retrieves the file corresponding to the class resource URL url = klass.getResource(resource); return new File(url.getFile()); |
File | getResourceAsFile(Class sourceClass, String reference) get Resource As File return new File(sourceClass.getResource(reference).toURI()); |
File | getResourceAsFile(Class> clazz, String fn) Get a file to read the raw contents of the given resource :) URL url = clazz.getResource(fn); if (url == null || url.getFile() == null) { throw new IOException("resource \"" + fn + "\" relative to " + clazz + " not found."); return new File(url.getFile()); |
File | getResourceAsFile(Class> clazz, String name) Returns a File for the specified resource, associated with the specified class. URL url = clazz.getResource(name); if (url == null) { throw new FileNotFoundException(name + " (resource not found)"); return new File(url.getFile()); |
File | getResourceAsFile(Class> clazz, String rscName) get Resource As File File file = null; try { final URL url = clazz.getClassLoader().getResource(rscName); if (url != null) file = new File(new URI(url.toString())); } catch (URISyntaxException e) { e.printStackTrace(); return file; |
File | getResourceAsFile(final Class> clazz, final String name) get Resource As File String absolutePath = getAbsolutePath(clazz, name); try { URL url = clazz.getResource(absolutePath); if (url != null) { return new File(url.toURI()); } else { return null; } catch (URISyntaxException ex) { return null; |
File | getResourceAsFile(final String filename, final Class theClass) get Resource As File try { final java.net.URL resURL = theClass.getClassLoader().getResource(filename); if (resURL != null) { return new File(resURL.getFile()); } catch (Exception e) { throw new IOException("Unable to open " + filename); throw new IOException("resURL==null Unable to open " + filename); |
File | getResourceAsFile(String name) Returns a File pointing to a resource, given its name. String resource = getResourceAsString(name); if (resource.startsWith("vfs:/")) ; resource.replace("vfs:/", "file:/"); return (resource == null) ? null : new File(resource); |