2

java.io.IOException: Value too large for defined data type将将近 2.1GB 的大文件上传到服务器时,我得到了一个。我的代码是:

     URL oUrl = new URL(servierUrl);
     HttpURLConnection  connection = (HttpURLConnection) oUrl.openConnection();
       connection.setDoOutput(true);
       connection.setRequestMethod("POST");
       connection.setRequestProperty("Connection", "Keep-Alive");
       connection.setRequestProperty("Content-Type", "multipart/form-       data");
       connection.setRequestProperty("Content-Length", String.valueOf(nChunkSize));
       connection.setConnectTimeout(1800000); 

     InputStream oFileInputStream = new FileInputStream(new File(sFilePath));

     OutputStream outputStream = new DataOutputStream(connection.getOutputStream());
     .
     .
     . // here I'm dividing the stream chunks, every chunk 5Mb and uploading the chuck  to server 
          but in the chunk #410 (5Mb * 410) it cause an exception return the exception as I mentioned above.
          before that every chunk I upload it success
     .
     .

所以请提供任何帮助。

4

1 回答 1

0

我的猜测是使用 int 来保存文件的长度。这在 2^31-1 或大约 20 亿字节处溢出。看起来像 http 库或输出流中的问题。您将需要分解该文件或将破坏组件替换为有效的组件。通过在堆栈跟踪中向上查找并查看崩溃来自何处,可以找到哪个组件正在破坏。

于 2013-08-19T14:54:37.707 回答