windows - 如何释放这些 .txt 文件的内存
问题描述
使用 TXT 文件我最近看到一条消息“无法创建文件 ('c:\01.txt') 进程无法访问该文件,因为它正被另一个进程使用”我如何释放这些 .txt 的内存文件?
我有尼斯先生的这段代码,当我尝试更改或添加新代码时:ListBox1.Items.savetofile('01.txt');
“无法创建文件('c:\01.txt')进程无法访问该文件,因为它正被另一个进程使用”
var
path: string;
SR: TSearchRec;
tempFile: TextFile;
line: string;
begin
path:= 'C:\my all txt\';
if FindFirst(path + '*.txt', faAnyFile, SR) = 0 then
begin
repeat
if (SR.Attr <> faDirectory) then
begin
AssignFile(tempFile, path + SR.Name);
Reset(tempFile);
while not Eof(tempFile) do
begin
Readln(tempFile, line);
ListBox1.Items.Add(line);
end;
end;
until FindNext(SR) <> 0;
FindClose(SR);
end;
end;
解决方案
完成文件后,您永远不会关闭它们。CloseFile
到达后您需要使用Eof(tempfile)
:
while not Eof(tempfile) do
begin
Readln(tempfile, line);
ListBox1.Items.Add(line);
end;
CloseFile(tempfile);
推荐阅读
- javascript - 登录谷歌后如何重定向到另一个页面?
- swift - 获取 .m3u 音频的时长
- php - 如何使用 PHP 设置透明度或着色背景图像?
- java - 如何将对象添加到数组中,该数组是java中类的实例变量
- angular - ng2-smart-table 的 crud 有一些问题
- amazon-web-services - AWS - Lambda 无法访问 EMR 的 Livy 端点
- javascript - 反应字符串过滤器方法返回空数组与.includes()条件
- php - PayPal WebHooks - Paypal-cert-url
- ssis - SQL Server Integration Services - 如何在 .dtsConfig 文件中获取当前日期并使用它生成文件名
- node.js - NodeJS / NPM / node-gyc / make - 有些东西不工作,无法安装 npm 模块 mdns