VB.NET 中的 Print() 方法是否适用于通过二进制访问打开的文件?
我正在尝试使用 Print() 方法将数据写入二进制文件,但是当我运行它时,我收到 System.IO 异常“错误文件模式”。有人知道这里出了什么问题吗?这是 FileOpen 声明的代码,可能与它有关?谢谢
FileOpen(filenumber, "path to file", OpenMode.Binary, OpenAccess.Write, OpenShare.LockReadWrite)
Print(filenumber, expression(variable))
I am trying to write data to a binary file using the Print() method, but when I run it I get the System.IO exception Bad File Mode. Does anybody have an idea of what's going wrong here? Here's the code for the FileOpen declaration, that might have something to do with it? Thanks
FileOpen(filenumber, "path to file", OpenMode.Binary, OpenAccess.Write, OpenShare.LockReadWrite)
Print(filenumber, expression(variable))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您为什么首先使用
Print
?包含该函数是为了向后兼容 VB 6 应用程序。如果您在 VB.NET 中编写新的应用程序,则应该使用不同的函数。快速开始工作的最简单方法是使用
My.Computer.FileSystem
对象读取和写入文件。这甚至比FileOpen
和Print
等旧函数提供了更好的性能。更多说明和示例代码可在 MSDN 上获取。具体来说:Why are you using
Print
in the first place? That function is included for backwards compatibility with VB 6 applications. If you're writing a new application in VB.NET, you should be using a different function.The easiest way to get off the ground quickly is using the
My.Computer.FileSystem
object to read and write to files. This even provides better performance than the legacy functions likeFileOpen
andPrint
. More explanation and sample code is available here on MSDN. Specifically: