各位好,本人初学Android,在用Http下载文件时出现一个奇怪的问题。
1.下面代码中得urlStr是正确的,我用IE和迅雷试过都可以下载。
2.在模拟器上调试没问题
3.在真机上调试时候如果用我们自己的服务器下载url为:http://**.**.**.**:8089/androiddata/dishes.zip会报文件未找到,可是吧url随便换位网络上的地址,例如http://c.csdn.net/bbs/t/5/i/pic_logo.gif就可以。这些问题在模拟器上都不会出现。请高手们帮忙看下,先谢谢了!  public boolean downLoadFile(String urlStr,String path,String fileName) throws IOException{
    url = new URL(urlStr);
    HttpURLConnection con = (HttpURLConnection) url.openConnection(); 
    int contentLength = con.getContentLength();
    int len;
    byte[] bs= new byte[1024];
    try 
    {
  InputStream is = con.getInputStream(); //这句异常,FileNotFoundException
  if (new Functions().isFolderExists(path) == false){
  new File(path).mkdir();  
  }
  OutputStream os = new FileOutputStream(new File(path+ fileName));
      while ((len = is.read(bs)) != -1) {                 
       os.write(bs, 0, len);             
       }            
      os.close();            
      is.close(); 
      return true;
    } 
    catch (IOException e) 
    {
     System.out.println("12345"+e.toString());
    return false;
    } 
}

解决方案 »

  1.   

    应该不是那句话报FileNotFoundException吧
      

  2.   

    是啊,我曾经注销了try{}catch{}其他的代码,只留了这句InputStream is = con.getInputStream();
      

  3.   

    是不是.zip的不可以。。换个别的文件试试。
      

  4.   

    图片也不行gif,jpg我直接放到根目录也不行疯了...
      

  5.   

    你先用调试试试, OutputStream os = new FileOutputStream(new File(path+ fileName));
    执行这句的时候,就报错了。。  为什么系统提示是你说的那句呢。  因为啊。。    outputStream有错,系统就会爆  对象错误的。。