通过HttpURLConnection上传文件有两种方式。
其中之一是:
while ((bytesRead = fileInputStream.read(buffer)) > 0) {
dataOutputStream.write(buffer, 0, (int)bytesRead);
}
另一个是:
while (bytesRead > 0) {
dataOutputStream.write(buffer, 0, bufferSize);
bytesAvailable = fileInputStream.available();
bufferSize = (int) Math.min(bytesAvailable, maxBufferSize);
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
}
它们之间有什么区别,哪个更好?