public static String readContent(String filename) throws IOException { FileChannel fc = null; try { fc = new RandomAccessFile(filename, "r").getChannel(); MappedByteBuffer byteBuffer = fc.map(MapMode.READ_ONLY, 0, fc.size()).load(); byte[] result = new byte[(int) fc.size()]; if (byteBuffer.remaining() > 0) { byteBuffer.get(result, 0, byteBuffer.remaining()); } String content = new String(result, CHARSET); return content; } catch (IOException e) { e.printStackTrace(); throw e; } finally { try { fc.close(); } catch (IOException e) { e.printStackTrace(); } } }
java快速读取大文件
猜你喜欢
转载自xiaoliang330.iteye.com/blog/2410547
今日推荐
周排行