Skip to content

Instantly share code, notes, and snippets.

@JaDogg
Created July 11, 2014 09:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JaDogg/4392fcac6ed9402b6e23 to your computer and use it in GitHub Desktop.
Save JaDogg/4392fcac6ed9402b6e23 to your computer and use it in GitHub Desktop.
Resource to byte Array
try {
InputStream is = this.getClass().getResourceAsStream(
"/classpath/dummy.png");
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int nRead;
byte[] data = new byte[16384];
while ((nRead = is.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, nRead);
}
buffer.flush();
//
//now use buffer.toByteArray();
//
} catch (IOException ex) {
//TODO handle IOException
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment