zoukankan      html  css  js  c++  java
  • bufferedreader操作文件出现Connection timed out异常

      int count=0;

      String urlStr ="http://地址";

      try 
      {
                URL url = new URL(urlStr);
                BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(),"GBK"));   
                String line=null;
                do
                {
                        line = reader.readLine();
                        if(line!=null)
                        {
                              str +=line;
                        }
                }
                while(line!=null);
                reader.close();
                count = 0;
                return str;
      }  
      catch (Exception e) 
      {
                e.printStackTrace();
                String qq01 = "网络异常01开始:("+e.getMessage()+")结束!";
                String qq02 = "网络异常02开始:("+e.getLocalizedMessage()+")结束!";
                System.out.println(qq01);
                System.out.println(qq02);
                count++;
                if("Connection timed out".equals(e.getMessage()) && count<3)//出现异常时连续调用两次
                {   
                        回调方法();
                }
                return "6";
      }

    国泰民安
  • 相关阅读:
    php max()函数 语法
    php min()函数 语法
    php mt_rand()函数 语法
    php rand()函数 语法
    php pi()函数 语法
    php trim()函数 语法
    php chop()函数 语法
    php rtrim()函数 语法
    php ltrim()函数 语法
    php is_file()函数 语法
  • 原文地址:https://www.cnblogs.com/jirglt/p/3069355.html
Copyright © 2011-2022 走看看