我能夠從http位置讀取小於2GB的文件。但是,如果我嘗試讀取大於2 GB的文件,我會得到異常。我沒有完全閱讀,而是以大塊閱讀。以下是我的代碼片段和異常消息。幫我櫃面,如果你有一個線索進行進一步2GB限制Java輸入流
BufferedOutputStream bos = new BufferedOutputStream(os);
URL url = new URL(fileName);
LOGGER.debug(url.toString());
URLConnection connection = url.openConnection();
LOGGER.debug("Before getting input stream 100 MB, open input stream::" + downloadFileName);
// BufferedInputStream in = new BufferedInputStream(url.openStream());
InputStream in = url.openStream();
// InputStreamReader inReader = new InputStreamReader(in);
// InputStream in = connection.getInputStream();
LOGGER.debug("Afters getting input stream, open inputstream::" + downloadFileName);
// in.
// LOGGER.debug("in1::" + in1);
final byte[] buffer = new byte[100 * 1024 * 1024]; // 100Mb
while (true)
{
LOGGER.debug("Reading..");
final int read = in.read(buffer);
LOGGER.debug("Read..");
if (read < 0)
{
break;
}
LOGGER.debug("Writing..");
bos.write(buffer, 0, read);
LOGGER.debug("Wrote..");
// bos.
}
你能/你有沒有試過改變JVM的最大堆大小? – bcr
您可以嘗試閱讀而不寫(註釋掉bos)並檢查它是否可以讀取超過2GB的數據? –
「連接重置」表示* remote peer *丟棄連接。您的問題可能與2 GB大小無關,如果是這樣,它就在*發件人*一方。 –