Delphi文件学习二 Standard Routines and I/O
2010-08-08 22:05
197 查看
unit Unit1; interface uses SysUtils, Classes, Controls, Forms,Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; OpenDialog1: TOpenDialog; SaveDialog1: TSaveDialog; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); VAR fromF,ToF: file; //无类型文件 NumRead,NumWritten:Integer; Buf : array[1..2048] of Char; begin if OpenDialog1.Execute then begin AssignFile(fromF,OpenDialog1.FileName); Reset(fromF,1); {记录长度为1代表数据传输,只对无类型文件可用} if SaveDialog1.Execute then begin AssignFile(ToF,SaveDialog1.FileName); Rewrite(TOF,1);{记录长度为1} Canvas.TextOut(10, 10, 'Copying ' + IntToStr(FileSize(FromF)) + ' bytes...'); repeat System.BlockRead(fromF,Buf,SizeOf(Buf),NumRead); System.BlockWrite(toF,Buf,NumRead,NumWritten); until (NumRead = 0) or (NumRead <> NumWritten); CloseFile(FromF); CloseFile(ToF); Canvas.TextOut(30,30,'Success'); end; end; end; end.
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; OpenDialog1: TOpenDialog; Memo1: TMemo; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} {Eof函数测试文件是否已到文件尾} procedure TForm1.Button1Click(Sender: TObject); var F: TextFile;{文本文件} Buf :String; begin if OpenDialog1.Execute then begin AssignFile(F,OpenDialog1.FileName);{邦定相关联文件} Reset(F);{只读方式打开文件} {EOF函数判断文件是否到尾部,如果是返回真,否为假} while not Eof(F) do begin ReadLn(F,Buf);//读取文件数据 Memo1.Lines.Add(Buf); end; CloseFile(F); //关闭文件 end; end; end.
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; OpenDialog1: TOpenDialog; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var F: TextFile; begin OpenDialog1.Title := 'Delete File'; if OpenDialog1.Execute then AssignFile(F,OpenDialog1.FileName); try Reset(F); if MessageDlg('Erase ' + OpenDialog1.FileName + '?', mtConfirmation, [mbYes, mbNo], 0) = mrYes then begin CloseFile(F); Erase(F); {移除文件,回收站找不到} MessageDlg('Delete the '+OpenDialog1.FileName +' Success',mtCustom,[mbOk],0); end; except on EInOutError do MessageDlg('File I/O error.', mtError, [mbOk], 0); end; end; end.
相关文章推荐
- Delphi文件学习 Standard Routines and I/O
- Delphi学习之一:Programs and units
- 学习实战完全笔记--JavaSE----流与文件(Streams and Files)
- Delphi进行CAD二次开发教学(1)——基础学习:运行、新建、打开图形文件
- [Shell学习笔记] 创建任意大小的文件And分割任意大小的文件
- JMeter学习-027-JMeter参数文件(脚本分发)路径问题:jmeter.threads.JMeterThread: Test failed! java.lang.IllegalArgumentException: File distributed.csv must exist and be readable解决方法
- delphi 资源文件管理 Resources and Images
- Delphi学习笔记六——文件路径相关的字符串操作
- Delphi学习笔记一——Delphi的项目文件简介
- 码农小汪-spring框架学习之8- Using JSR 330 Standard Annotations @Inject and @Named
- Delphi学习笔记六——文件路径相关的字符串操作
- Delphi学习笔记六——文件路径相关的字符串操作
- delphi下的ini文件学习
- Android(java)学习笔记143:android提供打开各种文件的API接口:setDataAndType
- 学习Delphi资源文件
- Delphi 2010学习笔记(1)---工程文件的结构与语法---2011-01-18
- Asp.net core 学习笔记 ( Area and Feature folder structure 文件结构 )
- delphi学习-各种文件介绍
- caffe学习笔记6:Blob,layer and net以及对应配置文件的编写
- Caffe 深度学习入门教程 Blob,Layer and Net以及对应配置文件的编写