private static void fileChunking() throws IOException {
InputStream is = null;
OutputStream os = null;
byte[] buffer;
int maxBufferSize = 102400;
int bytesRead, bytesAvailable, bufferSize;
int responsecode = 0;
String responsemessage = null;
bufferSize = Math.min(content.length, maxBufferSize);
buffer = new byte[bufferSize];
bytesRead = is.read(buffer, 0, bufferSize);
while (bytesRead > 0) {
os.write(buffer, 0, bufferSize);
bytesAvailable = is.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
bytesRead = is.read(buffer, 0, bufferSize);
}
is.close();
os.flush();
responsecode = con.getResponseCode();
responsemessage = con.getResponseMessage();
System.out.print(responsemessage);
}
代码在读取 bytesRead = is.read(buffer, 0, bufferSize); 时抛出异常 'Stream already open'