[求助] 急急!!高手进来解决个问题
下面的程序我打开一文件往里面随机写入数据,然后删除;但是我用恢复软件恢复出来以后是我以前的原始数据,但是我要是去掉删除的代码自己手动删除的话恢复出来的就是随机数据啦 不知道为什么 高手解答#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <time.h>
#define REWRITECOUNT 10//重写文件次数
int main(int argc,char *argv[])
{
DWORD dwsizelow,dwsizehigh;
DWORD dwRet;
char * Buffer;
UINT i,j;
HANDLE hFile=CreateFile( "E:\\3.txt ",
GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if(hFile==INVALID_HANDLE_VALUE)
{
printf( "Can 't open the file.\n ");
ExitProcess(0);
}
dwsizelow=GetFileSize(hFile,&dwsizehigh);
if(dwsizelow!=0xFFFFFFFF)
{
printf( "the file size is %u\n ",dwsizelow);
}
else
{
printf( "obtain the file length failed.\n ");
ExitProcess(0);
}
srand((int)time(0));
Buffer=(char *)malloc(dwsizelow*sizeof(char));
for(j=0;j <REWRITECOUNT;j++)
{
for(i=0;i <dwsizelow;i++)//Buffer数组内容随机产生
{
Buffer[i]=rand()%255;
printf( "%c ",Buffer[i]);
}
printf( "\n ");
WriteFile(hFile,Buffer,dwsizelow,&dwRet,NULL);//将Buffer数组写到文件中
SetFilePointer(hFile,0,NULL,FILE_BEGIN);//将文件指针调回文件开始处
}
free(Buffer);
CloseHandle(hFile);
if(DeleteFile( "E:\\3.txt "))//删除文件
{
printf( "delete file success.\n ");
}
else
{
printf( "delete file failed.%i\n ",GetLastError());
ExitProcess(0);
}
// ExitProcess(1);
}