how to save downloaded files in cache android

后端 未结 1 1686
有刺的猬
有刺的猬 2020-12-28 23:12

Hi i\'m streaming video from a website in my android application. I have a history option showing the last seen videos. I wonder if i can use cache so that when the user ent

相关标签:
1条回答
  • 2020-12-28 23:42

    It should help you.

        URLConnection cn = new URL(mediaUrl).openConnection();   
        cn.connect();   
        InputStream stream = cn.getInputStream();
    
        File downloadingMediaFile = new File(context.getCacheDir(), "downloadingMedia.dat");
    
        FileOutputStream out = new FileOutputStream(downloadingMediaFile);   
        byte buf[] = new byte[16384];
        do {
            int numread = stream.read(buf);   
            if (numread <= 0) break;   
            out.write(buf, 0, numread);
            // ... 
        } while (...);
    
    0 讨论(0)
提交回复
热议问题