一次读取整个文件

File f = new File(path);
String content = new Scanner(f).useDelimiter("\\Z").next();

\ Z 是 EOF(文件结束)符号。设置为分隔符时,扫描仪将读取填充,直到达到 EOF 标记。