0
在下面的代码中。我正在将文件读入一个小缓冲区(len = CHUNK_SIZE)而我只是想将此缓冲区写入outputstream。但即使我在每个块后冲洗,我都会遇到堆溢出异常。那么如果我想流小文件一切都很好。但不应该刷新也删除流中的所有数据?DataOutputStream内部保存整个缓冲区?
URL url = new URL(built);
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setDoOutput(true);
con.setDoInput(true);
con.setUseCaches(false);
//con.setChunkedStreamingMode(CHUNK_SIZE);
con.setRequestProperty("Content-Type", "multipart/form-data; boundary="
+ Boundary);
FileInputStream is = new FileInputStream(m_FileList.get(i));
DataOutputStream os = new DataOutputStream(con.getOutputStream());
// .....
while((read = is.read(temp, 0, CHUNK_SIZE)) != -1) {
bytesTotal += read;
os.write(temp, 0, read); // heap overflow here if the file is to big
os.flush();
}