java.io.IOException: BufferedInputStream is closed

android 开发中遇到了这样的异常,在2.3以下版本不会出现,在2.3及以上就会报出

原来的代码如下 

reader = new BufferedReader(inputStream, 10240);

 while ((oneLine = reader.readLine()) != null) {
        buffer.append(oneLine);
    }

解决方案:

改用下面的方法从网络中读取数据

  int count = 1024;
    int result = -1;
    char[] readChars = new char[count];
    String temp = null;
    do {

     result = reader.read(readChars, 0, count);
     if (result > 0) {
      temp = new String(readChars, 0, result);
      buffer.append(temp);
     }

    } while (result != -1);

据说这是android2.3及以上的版本的一个 bug

 

posted @ 2011-12-08 21:19  青香蕉  阅读(10635)  评论(0编辑  收藏  举报