Android - Store inputstream in file

前端 未结 7 2042
[愿得一人]
[愿得一人] 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:33

    There's the way of IOUtils:

    copy(InputStream input, OutputStream output)
    

    The code of it is similar to this :

    public static long copyStream(InputStream input, OutputStream output) throws IOException {
        long count = 0L;
        byte[] buffer = new byte[4096]; 
        for (int n; -1 != (n = input.read(buffer)); count += (long) n)
            output.write(buffer, 0, n);
        return count;
    }
    

提交回复
热议问题