List of utility methods to do Resource Path Get
URL | getResource(final String path) get Resource return Thread.currentThread().getContextClassLoader().getResource(path);
|
File | getResource(String path) get Resource URL bundleurl = Platform.getBundle("de.schenk.jrtrace.service.test").getEntry(path); try { URL fileURL = FileLocator.toFileURL(bundleurl); return new File(fileURL.toURI()); } catch (URISyntaxException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); ... |
URL | getResource(String path) Loads the resource from the class loader returned by #getClassLoader() . URL url = getClassLoader().getResource(path); if (url == null) throw new IllegalArgumentException("Unable to find resource at " + path); return url; |
File | getResource(String relativePath) get Resource if (Platform.isRunning()) { URL fileURL = Platform.getBundle(PLUGIN_ID).getEntry(relativePath); File file = null; try { if (FileLocator.resolve(fileURL).toString().indexOf(" ") > -1) { URL location = FileLocator.resolve(fileURL); URI resolvedUri = new URI(location.getProtocol(), location.getPath(), null); file = new File(resolvedUri); ... |
URL | getResource(String resourcePath) get Resource if (resourcePath == null) { return null; resourcePath = formatResource(resourcePath); URL url = getCurrentLoader().getResource(resourcePath); return url; |
File | getResourceAsFile(Object relativeTo, String relativePath) Get a File object from a resource on the classpath using the ClassLoader that loaded the given object. ClassLoader cl = relativeTo.getClass().getClassLoader(); URL url = cl.getResource(relativePath); URI uri; try { uri = url.toURI(); File f = new File(uri); return f; } catch (URISyntaxException e) { ... |
File | getResourceAsFile(String relativePath) get Resource As File URL url = Thread.currentThread().getContextClassLoader().getResource(relativePath); File file = new File(url.toURI()); return file; |
InputStream | getResourceAsStream(final String path) get Resource As Stream final URL resource = getResource(path); if (resource == null) { throw new IllegalStateException(path); return resource.openStream(); |
InputStream | getResourceAsStream(String resourcePath, ClassLoader classLoader, Class> clazz) Get the InputStream input stream to the resource given by the supplied path. if (resourcePath == null) throw new IllegalArgumentException("resourcePath may not be null"); InputStream result = null; if (classLoader != null) { result = classLoader.getResourceAsStream(resourcePath); if (result == null && clazz != null) { result = clazz.getResourceAsStream(resourcePath); ... |
String | getResourceAsString(String path) get Resource As String try { URL resource = Thread.currentThread().getContextClassLoader().getResource(path); if (resource != null) { return readFromStream(Thread.currentThread().getContextClassLoader().getResourceAsStream(path)); } else { throw new RuntimeException(new FileNotFoundException(path)); } catch (Exception e) { ... |