Discard unprintable characters returned in server's XML response
- by Penang
While trying to use the Bing API to search, I am getting characters that are not printable and do not seem to hold any extra information. The goal is to save the XML (UTF-8) response as a text file to be parsed later.
My code currently looks something like this:
URL url = new URL(queryURL);
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
BufferedWriter out = new BufferedWriter(new FileWriter(query+"-"+saveResultAs));
String str = in.readLine();
out.write(str);
in.close();
out.close();
When I send the contents of 'str' to console it looks something like this:
and here's a what the newly created local XML file looks like:
What should I be doing to convert the UTF-8 text so that str does not have the extra characters?