Posted By

pbehmer on 01/23/08


Tagged


Versions (?)

Read URL Bytes


 / Published in: Java
 

Reads the contents of a url and returns the text in a byte array.

  1. public byte[] readUrlBytes(String address) {
  2. byte[] byteReturn = null;
  3. URL theURL = null;
  4. InputStream inStream = null;
  5. try {
  6. theURL = new URL(address);
  7. inStream = theURL.openStream();
  8. byteReturn = readStream(inStream);
  9. } catch (IOException e) {
  10. e.printStackTrace();
  11. } finally {
  12. try {
  13. if (inStream != null) {
  14. inStream.close();
  15. }
  16. } catch (IOException e) {
  17. e.printStackTrace();
  18. }
  19. }
  20. return byteReturn;
  21. }

Report this snippet  

You need to login to post a comment.