私は4GBを超えるメインフレームのデータファイルを持っています。 500バイトごとにデータを読み込んで処理する必要があります。私はあなたが解決策で私を助けることができるしかし私にInteger.MAX_VALUEがファイルを読み込む> Javaで4GBのファイル
public void getFileContent(String fileName) {
RandomAccessFile aFile = null;
FileChannel inChannel = null;
try {
aFile = new RandomAccessFile(Paths.get(fileName).toFile(), "r");
inChannel = aFile.getChannel();
ByteBuffer buffer = ByteBuffer.allocate(500 * 100000);
while (inChannel.read(buffer) > 0) {
buffer.flip();
for (int i = 0; i < buffer.limit(); i++) {
byte[] data = new byte[500];
buffer.get(data);
processData(new String(data));
buffer.clear();
}
}
} catch (Exception ex) {
// TODO
} finally {
try {
inChannel.close();
aFile.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
を超えたメッセージでエラーを取得しています、のFileChannelを使用してみましたが?
例外とスタックトレースを表示 – assylias
'FileInputStream'を' BufferedInputStream'でラップすることができます。 – venture
これをチェックしてください - > http://stackoverflow.com/questions/8076472/why-does-filechannel-map-take-up-to-integer-max-value-of-data – Techidiot