快速创建大文件 Java

论坛 期权论坛 脚本     
匿名技术用户   2020-12-29 22:27   33   0

快速创建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();
}
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP