• Delphi 文件操作(2) Append


    在我们使用这个Append过程时我们先看看的过程参数
    Procedure Append(var F:Text);
       其中我们可以看到这个变量 F是一个TextFile类型的变量由此我们可以知道这个文件是对文本文件类型
    进行操作的过程,而这当中的F必须和外部的文件进行关联,如果F没有和外部的文件进行关联那么它将会抛出
    一个异常。如果F已经打开那么,它将会关闭F并从新打开。文件的指针将会设置在文件的末尾.


    下面我们就举个例子:

    unit Unit1;

    interface

    uses
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
    Dialogs, StdCtrls;

    type
    TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    private
    { Private declarations }
    public
    { Public declarations }
    end;

    var
    Form1: TForm1;

    implementation

    {$R *.dfm}

    procedure TForm1.Button1Click(Sender: TObject);
    var
    text:String;
    f:TextFile ;
    const
    filedir= 'c:\temp\test.txt';
    begin
    if not FileExists(filedir) then //这里用到了一个判断文件是否存在的函数
    begin
    ShowMessage('测试文件'+filedir+'不存在');
    Exit;
    end
    else
    begin

    AssignFile(f,filedir); //这里我们用到了AssignFile过程下面一节我会给大家介绍这个过程
    Append(f); //将文件指针定位到文件的末尾;
    write(f,'程序人生');//向文件Test.txt文件末尾写入数据”程序人生“;
    CloseFile(f); //对这个文件操作结束了,当然我们要关闭这个文件;

    end;

    end;

    end.
  • 相关阅读:
    Java中关键字优先级
    HashMap
    Mabatis通用SQL语句
    下滑线转换为驼峰
    常见问题整理
    常见问题整理
    VUE学习笔记(二)
    VUE学习笔记(一)
    获取鼠标位置
    VirtualBox NAT模式,设置虚拟机可上网,宿主机可访问虚拟机的方法
  • 原文地址:https://www.cnblogs.com/flay/p/2329518.html
Copyright © 2020-2023  润新知