return Paths.get(ClassLoader.getSystemResource(resourceName).toURI());
java.net.URL url = ClassLoader.getSystemResource("com/xyz/resources/camera.png");
/** * Resolves a URL for the underlying class path resource. * @return the resolved URL, or {@code null} if not resolvable */ @Nullable protected URL resolveURL() { if (this.clazz != null) { return this.clazz.getResource(this.path); } else if (this.classLoader != null) { return this.classLoader.getResource(this.path); } else { return ClassLoader.getSystemResource(this.path); } }
private File loadFromResources(String s) { return new File(ClassLoader.getSystemResource("ssl/" + s).getFile()); } }
public static ImageIcon getImageIcon(String resource) { URL imageURL = ClassLoader.getSystemResource(resource); ImageIcon image = new ImageIcon(imageURL); return image; }
// Load the directory as a resource URL dir_url = ClassLoader.getSystemResource(dir_path); // Turn the resource into a File object File dir = new File(dir_url.toURI()); // List the directory String files = dir.list()
public static String getFileFromClasspath(String name) { URL url = ClassLoader.getSystemResource(name); if (url == null) { throw new IllegalArgumentException("Could not find " + name); } return url.getPath(); }
/** * Resolves a URL for the underlying class path resource. * @return the resolved URL, or {@code null} if not resolvable */ @Nullable protected URL resolveURL() { if (this.clazz != null) { return this.clazz.getResource(this.path); } else if (this.classLoader != null) { return this.classLoader.getResource(this.path); } else { return ClassLoader.getSystemResource(this.path); } }
String path = resourceLocation.substring(CLASSPATH_URL_PREFIX.length()); ClassLoader cl = ClassUtils.getDefaultClassLoader(); URL url = (cl != null ? cl.getResource(path) : ClassLoader.getSystemResource(path)); if (url == null) { String description = "class path resource [" + path + "]";
String description = "class path resource [" + path + "]"; ClassLoader cl = ClassUtils.getDefaultClassLoader(); URL url = (cl != null ? cl.getResource(path) : ClassLoader.getSystemResource(path)); if (url == null) { throw new FileNotFoundException(description +
/** * 根据给定资源初始化URL */ private void initUrl() { if (null != this.clazz) { super.url = this.clazz.getResource(this.path); } else if (null != this.classLoader) { super.url = this.classLoader.getResource(this.path); } else { super.url = ClassLoader.getSystemResource(this.path); } if (null == super.url) { throw new NoResourceException("Resource of path [{}] not exist!", this.path); } }
/** * 根据给定资源初始化URL */ private void initUrl() { if (null != this.clazz) { super.url = this.clazz.getResource(this.path); } else if (null != this.classLoader) { super.url = this.classLoader.getResource(this.path); } else { super.url = ClassLoader.getSystemResource(this.path); } if (null == super.url) { throw new NoResourceException("Resource of path [{}] not exist!", this.path); } }
/** * Get the URL for this resource. * * @param object The object to grab the Classloader from. * This parameter is quite important from a * visibility of resources standpoint as the * hierarchy of Classloaders plays a role. * * @param resource The resource to load. * * @return If the Resource was found, the URL, otherwise null. * * @see Resource * @see #getResourceAsStream(Object,Resource) */ public static URL getResourceAsURL(Object object, Resource resource) { ClassLoader loader = object.getClass().getClassLoader(); URL url = null; if (loader != null) { url = loader.getResource(resource.getName()); } else { url = ClassLoader.getSystemResource(resource.getName()); } return (url); }
private File loadFromResources(String s) { return new File(ClassLoader.getSystemResource("ssl/" + s).getFile()); } }
/** {@inheritDoc} */ @Override public URL getResource(String name) { URL url = findResource(name); if (url == null) url = ClassLoader.getSystemResource(name); if (url == null) url = super.getResource(name); return url; }
public static File resourceAsFile(String resource) { try { URL systemResource = getSystemResource(resource); return new File(systemResource.toURI()); } catch (URISyntaxException e) { throw new AssertionError("URI syntax error:" + e.getMessage()); } } }
private static List<Block> loadBlocks(String path) throws URISyntaxException, IOException { URL url = ClassLoader.getSystemResource(path); File file = new File(url.toURI()); List<String> strData = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8); List<Block> blocks = new ArrayList<>(strData.size()); for (String rlp : strData) { blocks.add(new Block(decode(rlp))); } return blocks; }
private static List<Block> loadBlocks(String path) throws URISyntaxException, IOException { URL url = ClassLoader.getSystemResource(path); File file = new File(url.toURI()); List<String> strData = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8); List<Block> blocks = new ArrayList<>(strData.size()); for (String rlp : strData) { blocks.add(new Block(decode(rlp))); } return blocks; }
private static List<Block> loadBlocks(String path) throws URISyntaxException, IOException { URL url = ClassLoader.getSystemResource(path); File file = new File(url.toURI()); List<String> strData = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8); List<Block> blocks = new ArrayList<>(strData.size()); for (String rlp : strData) { blocks.add(new Block(decode(rlp))); } return blocks; }
@Before public void setup() throws URISyntaxException, IOException, InterruptedException { blockchain = createBlockchain((Genesis) Genesis.getInstance()); pendingState = ((BlockchainImpl) blockchain).getPendingState(); URL blocks = ClassLoader.getSystemResource("state/47250.dmp"); File file = new File(blocks.toURI()); strData = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8); for (int i = 0; i < 46000; i++) { Block b = new Block(Hex.decode(strData.get(i))); blockchain.tryToConnect(b); } }