如何对*.txt(文本文件)进行操作!!!
如:创建,删除,修改,读取其中某一行或者某一列,等等等等
关于其的所有操作函数!!!!谢谢老大们
如:创建,删除,修改,读取其中某一行或者某一列,等等等等
关于其的所有操作函数!!!!谢谢老大们
解决方案 »
- 大家平时用什么工具来写PDF电子书啊?
- ★★★★散分!!!!蛰伏了两个月时间,在新的一年到来的时候,自己DO了一个新的网站,大家PP吧^_^散分!!!!★★★★
- 散分:刚买的电脑就出问题,问了n个人,都不知道什么原因!
- 请问我的ADO程序为什么编译不过,是因为缺什么呢? 在线等待!!!
- 急!请教一个组件问题?
- 用delphi怎样实现:创建一个IIS 虚拟目录?
- EXCEL问题
- 关于全局对象的问题
- 菜鳥問題
- delphi如何实现数据分页显示?
- 请问哪里有李维的《Delphi 5.x ADO/MTS/COM+高级程序设计篇》完整版的下载?注:后四章内容
- 哪位老兄有多余的QQ,送我一个,100分相送!!
F: File of char;
a: Char;
begin
AssignFile(F,'C:\aa.txt'); //文件名你自己修改
Rewrite(F); //进行写操作,读操作用Reset(F);
WriteLn(F,'你的字符'); //写入一行 读入一行用Readln(F); 读入一个字符用read(f,a);
closeFile(F);
end;
or
AssignFile / Reset / Readln / Writeln / closefile
Description
Append Opens an existing text file for appending.
AssignFile Assigns the name of an external file to a file variable.
BlockRead Reads one or more records from an untyped file.
BlockWrite Writes one or more records into an untyped file.
ChDir Changes the current directory.
CloseFile Closes an open file.
Eof Returns the end-of-file status of a file.
Eoln Returns the end-of-line status of a text file.
Erase Erases an external file.
FilePos Returns the current file position of a typed or untyped file.
FileSize Returns the current size of a file; not used for text files.
Flush Flushes the buffer of an output text file.
GetDir Returns the current directory of a specified drive.
IOResult Returns an integer value that is the status of the last I/O function performed.
MkDir Creates a subdirectory.
Read Reads one or more values from a file into one or more variables.
Readln Does what Read does and then skips to beginning of next line in the text file.
Rename Renames an external file.
Reset Opens an existing file.
Rewrite Creates and opens a new file.
RmDir Removes an empty subdirectory.
Seek Moves the current position of a typed or untyped file to a specified component. Not used with text files.
SeekEof Returns the end-of-file status of a text file.
SeekEoln Returns the end-of-line status of a text file.
SetTextBuf Assigns an I/O buffer to a text file.
Truncate Truncates a typed or untyped file at the current file position.
Write Writes one or more values to a file.
Writeln Does the same as Write, and then writes an end-of-line er to the text file.
**********************************************
*等我有钱了,我就站在天安门广场挨个给大家发钱*
**********************************************
文件”。
利用文本文件保存数据的优点是:利用常见的文字编辑器就可以浏览其中的内容。在后
面常用函数的介绍中,如果具体的函数对于上述三类文件有不同的用法时,将做必要的说明。
同时,通过这些说明,读者可以领会三种文件类型的不同。
本节讲述使用内建于Object Pascal运行时库中的过程和函数处理文本文件的方法。在对
文本文z件进行任何处理之前,首先要打开此文本文件。声明变量:
var
MyTextFile:Textfile;
通过此变量可以来引用一个文本文件。
打开一个文件需要两步:首先是AssignFile() ,它可以将文件变量与一个文件关联起来。
例如:
AssignFile(MyTextFile,’MyTextFile.txt’);
这时,可以进行第二步:打开文件。有三种方式可以打开文件:使用Rewrite 过程创建
并打开文件;对于一个已存在的文件,此操作将使文件被覆盖;使用Reset 过程只读地打开
一个文件;使用Append 过程可以向已存在的文件追加文本。注意Reset 将以可读写方式打开
类型文件和无类型文件。
134 第6 章文件管理
可以使用CloseFile来关闭一个已打开的文件。下面我们来看几个例子。
下面的程序将以只读方式打开一个文件:
var
MyTextFile:Textfile;
begin
assignfile(MyTextfile,’MyTextFile.txt’);
reset(MyTextFile);
try
{操作文件}
finally
CloseFile(MyTextFile);
end;
end;
下面的程序将创建一个新的文件:
var
MyTextFile:Textfile;
begin
assignfile(MyTextfile,’MyTextFile.txt’);
rewrite(MyTextFile);
try
{操作文件}
finally
CloseFile(MyTextFile);
end;
end;
下面的程序将向一个已存在的文件追加新的文本:
var
MyTextFile:Textfile;
begin
assignfile(MyTextfile,’MyTextFile.txt’);
append(MyTextFile);
try
{操作文件}
finally
CloseFile(MyTextFile);
end;
end;