/** * 内存映射 * * @throws IOException */ public static void mapChannel() throws IOException { long t1 = System.currentTimeMillis(); FileInputStream in = new FileInputStream("d:/1.txt"); long size = in.available(); RandomAccessFile out = new RandomAccessFile("d:/2.txt", "rw"); FileChannel inc = in.getChannel(); MappedByteBuffer bf = inc.map(FileChannel.MapMode.READ_ONLY, 0, size); FileChannel outc = out.getChannel(); MappedByteBuffer outbf = outc.map(FileChannel.MapMode.READ_WRITE, 0, size); outbf.put(bf); inc.close(); outc.close(); in.close(); out.close(); long t2 = System.currentTimeMillis(); System.out.println(t2 - t1); } (完全的内存映射)读文件是最快的,比任何其它读取方式快40倍,但你要BufferedImage结果那只能读到内存了
67,513
社区成员
225,878
社区内容
加载中
试试用AI创作助手写篇文章吧