public final class Resources extends Object
Modifier and Type | Method and Description |
---|---|
static void |
copy(URL from,
OutputStream to)
Copies all bytes from a URL to an output stream.
|
static URL |
getResource(String resourceName)
|
static byte[] |
toByteArray(URL url)
Reads all bytes from a URL into a byte array.
|
static String |
toString(URL url,
Charset charset)
Reads all characters from a URL into a
String , using the given character set. |
public static URL getResource(String resourceName)
URL
pointing to resourceName
if the resource is found using the
context class loader. In simple environments, the
context class loader will find resources from the class path. In environments where different
threads can have different class loaders, for example app servers, the context class loader
will typically have been set to an appropriate loader for the current thread.
In the unusual case where the context class loader is null, the class loader that loaded
this class (Resources
) will be used instead.
IllegalArgumentException
- if the resource is not foundpublic static byte[] toByteArray(URL url) throws IOException
url
- the URL to read fromIOException
- if an I/O error occurspublic static String toString(URL url, Charset charset) throws IOException
String
, using the given character set.url
- the URL to read fromcharset
- the charset used to decode the input stream; see StandardCharsets
for helpful
predefined constantsIOException
- if an I/O error occurs.public static void copy(URL from, OutputStream to) throws IOException
from
- the URL to read fromto
- the output streamIOException
- if an I/O error occursCopyright © 2019. All rights reserved.