Search code examples
javahtmlarraysweb-crawlerbytearrayoutputstream

Saving an HTML resource in a byte array


I am trying to save a HTML resource in a file, as well as in a byte array. I have created a function to create a directory and a separate function called saveResource which will download an HTML file and store it in said directory. This part of the function works quite well and stores the correct html file corresponding to the URL that was inputted in the command line. However, I am having an issue storing this file into a byte array. The function returns a byte array of the contents of the resource specified by urlString. How can I write the function so that it also stores the HTML file in the byte array so that the array will have the correct contents?


Solution

  • "[B@d9438de" is the address (and type) of your byte array.

    You should print out the actual bytes in the array, not the reference.

    Edit: If you use a BufferedReader, you can read the HTML line by line into Strings and then you can perform any regular expression or indexOf searches that you want.