通过这次HttpURLConnection上传超大文件了解了更多内容:
1.Java nio的MappedByteBuffer(内存映射),更快更高效读取大文件,读取超过2g的大文件
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
public class MappedBiggerFileReader {
private MappedByteBuffer[] mappedBufArray;
private int count = 0;
private int number;
private FileInputStream fileIn;
private long fileLength;
private int arraySize;
private byte[] array;
public MappedBiggerFileReader(String filePath, int arraySize) throws IOException {
this.fileIn = new FileInputStream(filePath);
FileChannel fileChannel = fileIn.getChannel();
this.fileLength = fileChannel.size();
this.number = (int) Math.ceil((double) fileLength / (double) Integer.MAX_VALUE);
// 内存文件映射数组
this.mappedBufArray = new MappedByteBuffer[number];
long preLength = 0;
// 映射区域的大小