与在Linux系统上快速创建大文件相同, 我想在Windows系统上快速创建一个大文件。大的我想是5gb。内容并不重要。内置命令或短批处理文件将是更可取的,但如果没有其他简单的方法,我将接受应用程序。


当前回答

在C:\Temp中创建一个文件来填充磁盘C:只留下10 MB:

[io.file]::Create("C:\temp\bigblob.txt").SetLength((gwmi Win32_LogicalDisk -Filter "DeviceID='C:'").FreeSpace - 10MB).Close

其他回答

最近,我正在寻找一种方法来创建一个具有空间分配的大型虚拟文件。所有的解看起来都很尴尬。最后,我刚刚启动了Windows中的DISKPART实用程序(从Windows Vista开始嵌入):

DISKPART
CREATE VDISK FILE="C:\test.vhd" MAXIMUM=20000 TYPE=FIXED

其中MAXIMUM是最终的文件大小,这里是20gb。

fsutil file createnew <filename> <length>

其中<length>为字节单位。

例如,要创建一个名为'test'的1MB (Windows MB或MiB)文件,可以使用这段代码。

fsutil file createnew test 1048576

但是Fsutil需要管理权限。

Python中的简单回答:如果你需要创建一个大的真正的文本文件,我只是使用了一个简单的while循环,并能够在大约20秒内创建一个5gb的文件。我知道这很粗糙,但已经够快了。

outfile = open("outfile.log", "a+")

def write(outfile):
    outfile.write("hello world hello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello worldhello world"+"\n")
    return

i=0
while i < 1000000:
    write(outfile)
    i += 1
outfile.close()

在C:\Temp中创建一个文件来填充磁盘C:只留下10 MB:

[io.file]::Create("C:\temp\bigblob.txt").SetLength((gwmi Win32_LogicalDisk -Filter "DeviceID='C:'").FreeSpace - 10MB).Close

你可以试试下面的c++代码:

#include<stdlib.h>
#include<iostream>
#include<conio.h>
#include<fstream>
#using namespace std;

int main()
{
    int a;
    ofstream fcout ("big_file.txt");
    for(;;a += 1999999999){
        do{
            fcout << a;
        }
        while(!a);
    }
}

可能需要一些时间来生成,这取决于你的CPU速度…