Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/202.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 输入流错误_Android - Fatal编程技术网

Android 输入流错误

Android 输入流错误,android,Android,我在下载文件时遇到了一个奇怪的错误,我需要打开输入流,然后将读取的数据写入输出流…输入流不工作…调试时没有错误…但它似乎挂在那里,键盘上的F6似乎不工作…必须终止调试会话…我做错了什么 try{ URL url = new URL(pdfurl); URLConnection conexion = url.openConnection(); conexion.connect(); int lenghtOfFile = conex

我在下载文件时遇到了一个奇怪的错误,我需要打开输入流,然后将读取的数据写入输出流…输入流不工作…调试时没有错误…但它似乎挂在那里,键盘上的F6似乎不工作…必须终止调试会话…我做错了什么

 try{
        URL url = new URL(pdfurl);
        URLConnection conexion = url.openConnection();
        conexion.connect();

        int lenghtOfFile = conexion.getContentLength();
        Log.d("k", "Lenght of file: " + lenghtOfFile);
        //InputStream s=file
        InputStream s=url.openStream();
        InputStream input = new BufferedInputStream(s);
        OutputStream output = new FileOutputStream(file);

        byte data[] = new byte[1024];

        long total = 0;

         while ((count = input.read(data)) != -1) {
          total += count;
          publishProgress((int)((total*100)/lenghtOfFile));
          output.write(data, 0, count);
         }

         output.flush();
         output.close();
         input.close();
        } 
         catch (Exception e) 
        {
         download_flag = true;
         String s=e.getMessage().toString();
         Log.d("k","exception occured"+s);
        }

您可以尝试HttpGet请求:

HttpGet httpGet = new HttpGet(url);
HttpClient httpclient = new DefaultHttpClient();
// Execute HTTP Get Request
HttpResponse response = httpclient.execute(httpGet);
content = response.getEntity().getContent();

您是否在AndroidManifest.xml中添加了Internet权限?是的..我有..否则它将无法连接到服务器…我正在获取文件的长度。