35文本文件的读写
一、最后效果
二、代码:
1 procedure TForm1.Button1Click(Sender: TObject); 2 begin 3 if OpenDialog1.Execute then 4 Edit1.Text:=OpenDialog1.FileName; 5 end; 6 7 8 procedure TForm1.Button2Click(Sender: TObject); 9 var 10 SFileName,DFileName:string; 11 oh:Char; 12 F1,F2:TextFile; 13 begin 14 if SaveDialog1.Execute then 15 begin 16 Edit2.Text :=savedialog1.FileName ; 17 SFileName:=Edit1.Text; 18 DFileName:=Edit2.Text+'.txt'; 19 if Length(SFileName)<>0 then 20 begin 21 AssignFile(F1,SFileName); 22 Reset(F1); 23 If length(DFileName)<>0 then 24 begin 25 AssignFile(F2,DFileName); 26 Rewrite(F2); 27 while not Eof(F1) do 28 begin 29 Read(F1,oh); 30 write(f2,oh); 31 end; 32 33 34 CloseFile(F2); 35 end 36 else 37 ShowMessage('你没有输入目标文件名!'); 38 CloseFile(F1); 39 ShowMessage('复制完成!'); 40 end 41 else 42 ShowMessage('源文件名必须输入!'); 43 end; 44 end;
三、源文件下载
https://download.csdn.net/download/yanglu_115/88549131