delete selected content in a file

12 次查看(过去 30 天)
nt
nt 2013-8-28
I use fopen to create a file, and want to use \b to delete something, but it doesn't work. In the file, \b shows a rectangular. The code is as following
fileID = fopen('./data/newfile.txt','wt');
fprintf(fileID,'"aaaaa"');
fprintf(fileID,'\b\b');
fclose(fileID);

回答(1 个)

Walter Roberson
Walter Roberson 2013-8-28
The only reliable way to delete something in a text file is to open a new text file and copy all the content of the original file over to the new one except what you do not want to be there.
None of the operating systems that MATLAB runs on have the facility to delete in the middle of a file.
(If you were deleting only at the very end of the file, there are ways in the operating systems, but the ways are not supported by MATLAB)

类别

Help CenterFile Exchange 中查找有关 Low-Level File I/O 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by