/*
* @param filePath 文件路径
* @param bufferSize 缓冲区大小 e.g. 1024 * 1024 * 8=8M
* @throws Exception
*/
public static void memoryMappedRead(String filePath,int bufferSize) throws Exception {
File file = new File(filePath);
long length = file.length();
/**
* 获取系统的换行符, windows 为“\r\n”
*/
String enterStr = System.getProperty(“line.separator”, “\n”);
int lengthOfEnterStr = enterStr.length();
String preciousLastPartString = “”;
String currentFirstPartString = “”;
@SuppressWarnings(“resource”)
MappedByteBuffer mbb = new RandomAccessFile(filePath, “r”).getChannel()
.map(FileChannel.MapMode.READ_ONLY, 0, length);
StringBuilder strBuf = new StringBuilder("");
long begin = System.currentTimeMillis();
long cycle = length / bufferSize;
int mode = (int) (length % bufferSize);
boolean partStringFlag = false;
for (int i = 0; i < cycle; i++) {
byte[] bytes = new byte[bu