打开一个输出文件-恶意代码分析实战英文原版pdf
238 |第八章输入/输出函数
没有发现条目:0
条目为当前工作区的一个变量:1
条目为m文件或未知类型的文件:2
条目是一个MEX文件:3
条目是一个MDL文件:4
条目是一个内建函数:5
条目是一个p代码文件:6
条目是一个目录:7
例8.4 打开一个输出文件
这个程序从用户那里得到输出文件名,并检查它是否存在。如果存在,就询问用户是要把用新数据覆盖这个文件,还是要把新的数据添加到这个文件中。如果这个文件不存在,那么这个程序就会很容易地打开输出文件。
% Script file: output.m
% Purpose: To demonstrate opening an output file properly. This program checks for the existence of an output file. If it exists, the program checks to see if the old file should be deleted, or if the new data should be appended to the old file.
% Record of revisions:
% Date Programmer Description of change
% 11/29/98 S. J. Chapman Original code
% Define variables:
% fid -- File id
% out_filename -- Output file name
% yn -- Yes/No response
% Get the output file name.
out_filename = input('Enter output filename: ','s');
% Check to see if the file exists.
if exist(out_filename,'file')
% The file exists
disp('Output file already exists.');
yn = input('Keep existing file? (y/n) ','s');
if yn == 'n'
fid = fopen(out_filename,'wt');
else
fid = fopen(out_filename,'at');
end
else
% File doesn't exist
fid = fopen(out_filename,'wt');
end
% Output data
fprintf(fid,'%s ',date);
% Close file
fclose(fid);
当这个程序执行后,产生的结果为"。
你可能会想了解更多关于Matlab文件操作的具体例子和代码示例,那么请访问以下链接:
-
Matlab文件操作演示及示例代码:这个链接提供了详细的Matlab文件操作示例,帮助你更好地理解如何在Matlab中进行文件操作。
-
python操作toml文件的示例代码:如果你对Python也感兴趣,这个链接展示了如何操作TOML文件的示例代码。
-
C语言文件IO操作示例代码:对于喜欢C语言的读者,这里有详细的文件IO操作示例代码。