I want to save an RSS feed to an xml document on my computer. I’m using XPath with Java to parse the XML myself, so all I want is a file that contains the source (XML) I see when I view the source of the website’s RSS page.
In other words, instead of copying and pasting the source of the RSS page into a file I save as an XML file, I’d like to write a program that pulls this for me.
You don’t even need to introduce a library to do that!
Simply get an
URL-object on the Rss-Feed you want to “download” and use theopenConnection()-method to get anURLConnection.You can then use it’s
getInputStream()-method. From this InputStream you can read the unparsed source of the RSS document (you should wrapp it with aBufferedInputStream).This can then be saved as a String (in memory) or directly written to the HDD by using a
FileOutputStream.An example-implementation can be found here: https://gist.github.com/2320294