How to open a binary file that returns -1 when using fopen?
9 次查看(过去 30 天)
显示 更早的评论
I am trying to open a file that someone else recorded. The file is supposedly binary. The extension is meaningless (it refers to the content of the file...). I tried using fopen and the file identifier is -1 (so can't read it in). If I 'manually' open the file it does not show as binary but as many symbols. How can I approach this?
Thank you
0 个评论
回答(2 个)
Walter Roberson
2017-4-29
Use
filename = 'NameOfBinaryFile';
[fid, msg] = fopen(filename, 'r');
if fid < 0
error('Could not open file "%s" because: "%s"', filename, msg);
end
For example it might be in use by another program, or you might not have permission to read it.
2 个评论
Walter Roberson
2017-4-29
Currently you do not know why the fopen fails. The above code will tell you why. It has nothing to do with making your program available to others: it has to do with debugging a problem with your program or configuration.
Image Analyst
2017-4-29
Check the file attributes. If it's marked at readonly and you're trying to open it for writing, it might return -1. Make sure the readonly checkbox is not checked.
0 个评论
另请参阅
类别
在 Help Center 和 File 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!