Search code examples
androiddownloadioexceptionandroid-2.3-gingerbread

File downloading returns IOException with Android 2.3


I have a code that downloads and reads text files, but it returns IOException with Android 2.3. It works well with other versions.

Duplicate of this same problem is here but none of those tips helped and I'm currently trying the trick at this page. I also have the custom DoneHandlerInputStream class in my code.

Code:

URL url = new URL(URLstr);
URLConnection connection = url.openConnection(); 

BufferedReader rd;

InputStream stream = connection.getInputStream();
stream = new DoneHandlerInputStream(stream);
rd = new BufferedReader(new InputStreamReader(stream));

StringBuffer sb = new StringBuffer();
String line;
while ((line = rd.readLine()) != null){
    sb.append(line);
}
rd.close();

String resultedString = sb.toString();

Solution

  • have u try this?
    
    while((line = rd.readLine()) != null)
    {
        sb.append(line);
        if (!rd.ready()) {
           break;
        }
    }
    rd.close();