如何在此代码中实现 60 秒超时?此代码打开一个 URL,下载纯文本,并将输出作为字符串变量发送。有效,但有时会挂起,我必须重新开始。我希望能在 60 秒后超时并返回检索到的任何数据。请不要建议使用 Apache 等外部库。如果我可以自己编辑此代码,那就更好了。public static String readURL( URL url ){ try { // open the url stream, wrap it an a few "readers" BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())); String s=""; String line=""; while ((line = reader.readLine()) != null) { s=s+"\r\n"+line; } reader.close(); return s; }catch(Exception e){ StringWriter errors = new StringWriter(); e.printStackTrace(new PrintWriter(errors)); return errors.toString(); }}//end method
添加回答
举报
0/150
提交
取消