Skip to content

Instantly share code, notes, and snippets.

@dustinschultz
Created July 9, 2013 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dustinschultz/5959657 to your computer and use it in GitHub Desktop.
Save dustinschultz/5959657 to your computer and use it in GitHub Desktop.
Read a URL using a Scanner instead of the tedious BufferedReader
public static void main(final String[] args) {
Scanner out = null;
try {
out = new Scanner(new URL( "http://demo.further.utah.edu:9000/dts/rest/translate/5102/Code%20in%20Source/"
+ "41759-2/32868/Local%20Code?view=HUMAN").openStream(), "UTF-8")
.useDelimiter("\\A");
final String result = out.next();
if (result.indexOf("propertyValue") == -1) {
// do something
}
}
catch (final MalformedURLException e) {
// TODO Auto-generated catch block e.printStackTrace();
}
catch (final IOException e) {
// TODO Auto-generated catch block e.printStackTrace();
}
finally {
if (out != null) {
out.close();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment