快速创建大文件 Java

xiaoxiao2021-02-28  42

快速创建3G大文件,耗时不到1S,写下载器可以用到。

Path path = Paths.get("d:\\a.txt"); byte[] output = new byte[1]; ByteBuffer bf = ByteBuffer.wrap(output); try(FileChannel fc = FileChannel.open(path, WRITE, CREATE)) { fc.position((3L << 30) - 1); fc.write(bf); } catch (IOException e) { e.printStackTrace(); }
转载请注明原文地址: https://www.6miu.com/read-2299990.html

最新回复(0)