Android - Store inputstream in file

前端 未结 7 2022
[愿得一人]
[愿得一人] 2020-12-02 11:56

I am retrieveing an XML feed from a url and then parsing it. What I need to do is also store that internally to the phone so that when there is no internet connection it can

相关标签:
7条回答
  • 2020-12-02 12:44
    1. In your application's build.gradle file add under dependencies:
        implementation 'commons-io:commons-io:2.5'
    
    1. In your code:
    import org.apache.commons.io.FileUtils;
    
    // given you have a stream, e.g.
    InputStream inputStream = getContext().getContentResolver().openInputStream(uri);
    
    // you can now write it to a file with
    FileUtils.copyToFile(inputStream, new File("myfile.txt"));
    
    
    0 讨论(0)
提交回复
热议问题