Cấu trúc:
assign(<tên biến tệp>,<tên tệp>); Mở tệp
Close(<tên biến tệp>); Đóng tệp
VD:
Chương trình đọc dữ liệu tệp (đọc một biến n từ tệp):
uses crt;
var f:text; // Khai bao bien tep
n:longint;
begin
clrscr;
assign(f,'input.pas');reset(f); // Mo tep
readln(f,n); // Doc bien n tu tep
write(n);
close(f); //Dong tep
readln
end.
Chương trình ghi dữ liệu vao tệp (ghi một biến n vào tệp):
uses crt;
var f:text; // Khai bao bien tep
n:longint;
begin
clrscr;
assign(f,'output.pas');rewrite(f); // Mo tep
write('n=');readln(n);
write(f,n); // Ghi bien n vao tep
close(f); //Dong tep
readln
end.