Thursday, 12 September 2013

Java. need to read a url as string and timeout option

Java. need to read a url as string and timeout option

already asked in another post, but got no solution see me script bellow,
how can i change that, please full demo, so that i can set a readtimout if
the network is down for example
at all i have to connect to an url, read just one line, get that as a
string ... done hope u can give an example. any other working way is
welcome.. thx
try {
URL url = new URL("http://mydomain/myfile.php");
//url.setReadTimeout(5000); does not work
InputStreamReader testi= new InputStreamReader(url.openStream());
BufferedReader in = new BufferedReader(testi);
//in.setReadTimeout(5000); does not work
stri = in.readLine();
Log.v ("GotThat: ",stri);
in.close();
} catch (MalformedURLException e) {
} catch (IOException e) {
}

No comments:

Post a Comment