http上传大文件时OOM问题


1.连接
HttpURLConnection con = (HttpURLConnection)new URL("url").openConnection();
2.设置输出流的固定长度
    1)已知输出流的长度用setFixedLengthStreamingMode()
        con.setFixedLengthStreamingMode(输出流的固定长度)
    2)位置输出流的长度用setChunkedStreamingMode()
con.setChunkedStreamingMode(块的大小);
    如果没有用到以上两种方式,则会在本地缓存后一次输出,那么当向输出流写入超过40M的大文件时会导致OutOfMemory
3,其他设置
con.setTimeout()
con.setRequestMethod()
con.setDoOutput()
con.setReadTimeout()
con.setRequestProperty()
con.connect()
发布了22 篇原创文章 · 获赞 9 · 访问量 12万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章