public static void main(String[] args) throws Exception {
File file = new File("E:/a.txt"); // 100M
long start = System.currentTimeMillis();
String lastLine = readLastLine(file, "gbk");
long delt = System.currentTimeMillis() - start;
System.out.println(lastLine);
System.out.println("读取时间(毫秒):" + delt);
file = new File("E:/b.txt");// 仅一行文字
start = System.currentTimeMillis();
lastLine = readLastLine(file, "gbk");
delt = System.currentTimeMillis() - start;
System.out.println(lastLine);
System.out.println("读取时间(毫秒):" + delt);
}
public static String readLastLine(File file, String charset) throws IOException {
if (!file.exists() || file.isDirectory() || !file.canRead()) {
return null;
}
R