当我在Pascal中写入外部文件时,即使编码完美无缺,外部文件也不会完全写入。
procedure save;
{Menyimpan data penerbangan ke dalam file eksternal}
begin
write('> ');
write('nama file: ');
readln(namafisik);
assign(d,namafisik);
{$I-};
rewrite(d);
{$I+};
if (IOresult=0) then
begin
for i:=1 to Neff do
writejadwal(i);
end;
end;
procedure writejadwal(i:integer);
{Menuliskan jadwal ke file eksternal pada indeks ke-i}
begin
write(d,T.KodePenerbangan[i]);
write(d,' | ');
write(d,T.KotaKeberangkatan[i]);
write(d,' | ');
write(d,T.KotaKedatangan[i]);
write(d,' | ');
if ((T.TKeberangkatan[i].Day) < 10 ) then
begin
x:=T.TKeberangkatan[i].Day;
str(x,y);
s:=y;
write(d,'0'+s);
end
else
begin
write(d,T.TKeberangkatan[i].Day);
end;
write(d,':');
if ((T.TKeberangkatan[i].Month) < 10 ) then
begin
x:=T.TKeberangkatan[i].Month;
str(x,y);
write(d,'0'+y);
end
else
begin
write(d,T.TKeberangkatan[i].Month);
end;
write(d,':');
write(d,T.TKeberangkatan[i].Year);
write(d,' | ');
if ((T.TKeberangkatan[i].Hour) < 10 ) then
begin
x:=T.TKeberangkatan[i].Hour;
str(x,y);
write(d,'0'+y);
end
else
begin
write(d,T.TKeberangkatan[i].Hour);
end;
write(d,':');
if ((T.TKeberangkatan[i].Minute) < 10 ) then
begin
x:=T.TKeberangkatan[i].Minute;
str(x,y);
write(d,'0'+y);
end
else
begin
write(d,T.TKeberangkatan[i].Minute);
end;
write(d,' | ');
if ((T.TKedatangan[i].Day) < 10 ) then
begin
x:=T.TKedatangan[i].Day;
str(x,y);
s:=y;
write(d,'0'+s);
end
else
begin
write(d,T.TKedatangan[i].Day);
end;
write(d,':');
if ((T.TKedatangan[i].Month) < 10 ) then
begin
x:=T.TKedatangan[i].Month;
str(x,y);
s:=y;
write(d,'0'+s);
end
else
begin
write(d,T.TKedatangan[i].Month);
end;
write(d,':');
write(d,T.TKedatangan[i].Year);
write(d,' | ');
if ((T.TKedatangan[i].Hour) < 10 ) then
begin
x:=T.TKedatangan[i].Hour;
str(x,y);
write(d,'0'+y);
end
else
begin
write(d,T.TKedatangan[i].Hour);
end;
write(d,':');
if ((T.TKedatangan[i].Minute) < 10 ) then
begin
x:=T.TKedatangan[i].Minute;
str(x,y);
write(d,'0'+y);
end
else
begin
write(d,T.TKedatangan[i].Minute);
end;
write(d,' | ');
if (T.TKedatanganImplementasi[i].Day=0) then
writeln(d,'__:__:____ | __:__ | __:__:____ | __:__')
else
{MULAI}
begin
if ((T.TKeberangkatanImplementasi[i].Day) < 10 ) then
begin
x:=T.TKeberangkatanImplementasi[i].Day;
str(x,y);
s:=y;
write(d,'0'+s);
end
else
begin
write(d,T.TKeberangkatanImplementasi[i].Day);
end;
write(d,':');
if ((T.TKeberangkatanImplementasi[i].Month) < 10 ) then
begin
x:=T.TKeberangkatanImplementasi[i].Month;
str(x,y);
write(d,'0'+y);
end
else
begin
write(d,T.TKeberangkatanImplementasi[i].Month);
end;
write(d,':');
write(d,T.TKeberangkatanImplementasi[i].Year);
write(d,' | ');
if ((T.TKeberangkatanImplementasi[i].Hour) < 10 ) then
begin
x:=T.TKeberangkatanImplementasi[i].Hour;
str(x,y);
write(d,'0'+y);
end
else
begin
write(d,T.TKeberangkatanImplementasi[i].Hour);
end;
write(d,':');
if ((T.TKeberangkatanImplementasi[i].Minute) < 10 ) then
begin
x:=T.TKeberangkatanImplementasi[i].Minute;
str(x,y);
write(d,'0'+y);
end
else
begin
write(d,T.TKeberangkatanImplementasi[i].Minute);
end;
write(d,' | ');
if ((T.TKedatanganImplementasi[i].Day) < 10 ) then
begin
x:=T.TKedatanganImplementasi[i].Day;
str(x,y);
s:=y;
write(d,'0'+s);
end
else
begin
write(d,T.TKedatanganImplementasi[i].Day);
end;
write(d,':');
if ((T.TKedatanganImplementasi[i].Month) < 10 ) then
begin
x:=T.TKedatanganImplementasi[i].Month;
str(x,y);
s:=y;
write(d,'0'+s);
end
else
begin
write(d,T.TKedatanganImplementasi[i].Month);
end;
write(d,':');
write(d,T.TKedatanganImplementasi[i].Year);
write(d,' | ');
if ((T.TKedatanganImplementasi[i].Hour) < 10 ) then
begin
x:=T.TKedatanganImplementasi[i].Hour;
str(x,y);
write(d,'0'+y);
end
else
begin
write(d,T.TKedatanganImplementasi[i].Hour);
end;
write(d,':');
if ((T.TKedatanganImplementasi[i].Minute) < 10 ) then
begin
x:=T.TKedatanganImplementasi[i].Minute;
str(x,y);
write(d,'0'+y);
end
else
begin
write(d,T.TKedatanganImplementasi[i].Minute);
end;
writeln(d);
end;
{SELESAI}
end;
顺便说一下jadwal是印尼语的英文
代码并不完美。特别是,你似乎没有关闭文件。
问题是您不关闭或冲洗。大多数语言都尽量减少对操作系统的写入调用,并且只在累积了足够的字节时才写入。(标准128字节,但可以通过settextbuf增加)。可能你的文件是128字节的倍数。
flush或close将缓冲区的剩余部分写出来。