java fast read large file

	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 ();
			}
		}
	}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326222252&siteId=291194637