SQLiteDatabaseCorruptException: database disk image is malformed

后端 未结 1 677
长情又很酷
长情又很酷 2021-01-14 03:52

I\'ve run into a wall with my program on this one. I\'ve searched around the internet for a solution to this problem but I haven\'t been able to find one so here goes..

相关标签:
1条回答
  • 2021-01-14 04:14

    Yeah. You're not actually copying the file.

    public void downloadFile(String file_name) throws IOException {
    
        URL url = new URL(file_url + file_name);
        URLConnection connection = url.openConnection();
        InputStream response = connection.getInputStream();
    
        FileOutputStream fos = new FileOutputStream(local_file_path + file_name);
        byte data[] = new byte[1024];
    
        //WHERE'S THE BEEF?
    
        fos.write(data);
        fos.close();
        response.close();
    }
    

    Also, manually writing that copy code is error prone. I made a trimmed down version of apache commons:

    http://www.touchlab.co/blog/android-mini-commons/

    Call

    IOUtils.copy(response, fos);
    
    0 讨论(0)
提交回复
热议问题