Created
July 9, 2013 18:02
-
-
Save dustinschultz/5959657 to your computer and use it in GitHub Desktop.
Read a URL using a Scanner instead of the tedious BufferedReader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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