iValue := 1234;
strFile := 'c:\1.txt';//已经存在但为空!
fHandle := FileOpen( strFile, fmOpenWrite );
FileSeek( fHandle, 0, 0);//point to the end of file
strValue := IntToStr( iValue ) + ' ';
FileWrite( fHandle, strValue , sizeof(strValue) );
FileClose( fHandle );
其中 iValue : integer;
strPath, strFile, strValue : string;
fHandle : Integer;
按理c:\1.txt应该有内容为:1234,可是没有!为什么?难道File×这一套不管用?
strFile := 'c:\1.txt';//已经存在但为空!
fHandle := FileOpen( strFile, fmOpenWrite );
FileSeek( fHandle, 0, 0);//point to the end of file
strValue := IntToStr( iValue ) + ' ';
FileWrite( fHandle, strValue , sizeof(strValue) );
FileClose( fHandle );
其中 iValue : integer;
strPath, strFile, strValue : string;
fHandle : Integer;
按理c:\1.txt应该有内容为:1234,可是没有!为什么?难道File×这一套不管用?
t :TextFile;
begin
AssignFile(t, 'C:\1.txt');
Rewrite(t);
try
Writeln(t, '1234');
finally
CloseFile(t);
end;
end;
var
iValue : integer;
strPath, strFile, strValue : string;
fHandle : Integer;
sV:array [1..4] of char;//用字符数组
begin
iValue := 1234;
strFile := 'c:\1.txt';//已经存在但为空!
fHandle := FileOpen( strFile, fmOpenWrite );
FileSeek( fHandle, 0, 0);//point to the end of file
strValue := '1234';
sv:='1234';
FileWrite( fHandle, sv , High(sv));;//用字符数组
FileClose( fHandle );
end;
FileWrite( fHandle, '1234' , sizeof('1234') );
其实STRING类型的第一个字节记录了字符串的长度。
你可以把strValue[0]的值取出来看看是多少?别告诉我不知道呀!给你几种方法解决你的问题:
1、FileWrite(fHandle, strValue[1] , Length(StrValue));//注意不是Sizeof2、定义 buf : PChar;
StrLen : Integer;
iValue := 1234;
strFile := 'c:\1.txt';//
fHandle := FileOpen( strFile, fmOpenWrite );
FileSeek( fHandle, 0, 0);//point to the end of file
strValue := IntToStr( iValue ) + ' ';StrLen := Length(strValue);
getmem(buf,StrLen); //获取内存缓冲区
copyMemory(buf,Pchar(strValue),StrLen); //拷贝strValue到buf中.
FileWrite( fHandle,Buf^,StrLen);
FileClose( fHandle );
freeMem(buf); //释放内存