RandomAccessFile读取超大文件 随机读一行

public static void readBigFile(File file) throws IOException {
String fileName = file.getAbsolutePath();
RandomAccessFile randomFile = null;
randomFile = new RandomAccessFile(fileName, "r");
long fileLength = randomFile.length();
System.out.println("文件大小:" + fileLength);
long start = 0;
if (fileLength > 300) {
start = (long) (Math.random() * 50) + (fileLength - 300);
}

randomFile.seek(start);
// byte[] bytes = new byte[512];
int byteread = 0;
String currentLing = randomFile.readLine();
Log.e("random", currentLing);
String nextLine = randomFile.readLine();
Log.e("random", nextLine);
if (randomFile != null) {
randomFile.close();
}
}

你可能感兴趣的:(RandomAccessFile读取超大文件 随机读一行)