名侦探柯南621告白:Delphi文件

来源:百度文库 编辑:高考问答 时间:2024/04/24 13:22:49
如何在Delphi中实现文本文件以及二进制文件的读写?麻烦详细点

直接给你程序,上面有说明自己看一下就明白~~~也可以直接照用~

写入文件

Var

F : Textfile; //申明变量

Begin

AssignFile(F,'c:\ek.txt'); //让变量F和C:\ek.txt关连

ReWrite(F); {Create a new file named ek.txt}

Writeln(F,'你要写入文本文件的内容'); //写入文件

Closefile(F); //释放变量F

End;

读取文件

Var

F : Textfile;

str:String;

Begin

AssignFile(F

'c:\ek.txt'); {Assigns the Filename}

Reset(F); {Opens the file for reading}

Readln(F

str);

ShowMessage('1. line of textfile:' +str);

Closefile(F); {Closes file F}

End;

用文本输入框写点程序就行了。