帮助中心帮助中心
关闭一个或所有打开的文件
fclose(fileID)
fclose('all')
status = fclose(___)
示例
fclose(fileID) 关闭打开的文件。
fileID
fclose('all') 关闭所有打开的文件。
当关闭操作成功时,status = fclose(___) 将返回 status 0。否则,将返回 -1。您可以将此语法与前面语法中的任何输入参数结合使用。
status
0
-1
全部折叠
打开 badpoem.txt 文件,读取第一行,然后关闭该文件。
badpoem.txt
使用 fopen 打开文件。此函数将指定一个唯一的文件 ID,用于读取和写入文件。
fopen
fid = fopen('badpoem.txt')
fid = 3
使用 fgetl 读取文件的第一行。
fgetl
fgetl(fid)
ans = 'Oranges and lemons,'
关闭文件。
fclose(fid);
已打开文件的文件标识符,指定为整数。使用 fclose 关闭文件之前,必须使用 fopen 打开文件并获取其 fileID。
fclose
数据类型: double
double
backgroundPool
ThreadPool
用法说明和限制:
在基于线程的环境中不支持 fclose('all') 语法。
全部展开
此函数支持基于线程的环境。
ferror | fopen | frewind | fseek | ftell | feof | fscanf | fprintf | fread | fwrite
ferror
frewind
fseek
ftell
feof
fscanf
fprintf
fread
fwrite
您曾对此示例进行过修改。是否要打开带有您的编辑的示例?
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office