I read from a URL
type in Java and get the output line by line. But if the page didn't exist, it throws a 404
error code.
How can I add a check if the response code is 200
(and not 404
), get the line? And if it is 404
, print something.
url = new URL("http://my.address.com/getfile/12345.txt");
Scanner s = new Scanner(url.openStream());
while (s.hasNextLine()) {
s.nextLine();
break;
}