I'm still pretty new to java and I'm trying to learn how to open url's through script. From what I understand, two of the ways to do this are:
- 1. Directly use URL.getContent()
- 2. Creating a URLConnection object, then using it to open the connection and subsequently, an input stream from which you can read the information.
The question is, in what scenario would the latter be better than the prior? My first impressions are that method 1 would obviously be much faster (I'm guessing it's the equivalent of a GET command when we attempt to retrieve content via the browser.
Also, if I were to open a connection object to say, www.google.com, is there a way for me to open input streams based on extra url information:
Example www.google.com/herp/derp/hello.html, where the string in bold is dynamic,
without having to close the existing connection object? If so, how is this done?
+Will I experience memory leaks if I don't properly destroy objects that are no longer used? Or does Java handle that automatically?