-1
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'

4

1 回答 1

1

您可能已经getReader()在其他地方调用过与getInputStream(). 很难从这段代码中说出来,而且这个答案有点不太可能。

您更有可能从 servlet 字段或某个公共变量中获取 InputStream,并且有两个请求进行读取。

于 2012-05-07T10:03:51.727 回答