IO 异常是未处理的错误 [英] IO Exception was unhandled error
问题描述
代码:
[浏览器.vb]
...
Private Sub Browser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If My.Computer.FileSystem.FileExists(DefaultHomePageSavedLocation) = False Then
My.Computer.FileSystem.CreateDirectory("C:\ToolBoxData\TinyBrowser\")
File.Create(DefaultHomePageSavedLocation)
My.Computer.FileSystem.WriteAllText(DefaultHomePageSavedLocation, "http://hk.yahoo.com", True)
End If
End Sub
[setting.vb]
[setting.vb]
...
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
My.Computer.FileSystem.DeleteFile("C:\ToolBoxData\TinyBrowser\Home.txt")
File.Create("C:\ToolBoxData\TinyBrowser\Home.txt")
My.Computer.FileSystem.WriteAllText("C:\ToolBoxData\TinyBrowser\Home.txt", TextBox1.Text, True)
End Sub
所以显示了一条错误消息:
So a error message was shown:
IO 异常未处理.
请帮忙.
推荐答案
如果您查看 File.Create Method 你会看到它是一个函数,它返回一个提供对路径中指定文件的读/写访问的文件流".这意味着文件已打开.如果您查看 FileSystem.WriteAllText 的文档方法你会看到不需要事先创建文件,也没有以文件流为参数的重载.
If you look at the documentation for the File.Create Method you will see that it is a function which returns "A FileStream that provides read/write access to the file specified in path." This implies that the file is open. If you look at the docs for the FileSystem.WriteAllText Method you will see that you do not need to create the file beforehand, and there is no overload which takes a filestream as a parameter.
所以,取出 File.Create
行.
请记住告诉我们以后哪一行产生了错误.
Please remember to tell us which line generated the error in future.
这篇关于IO 异常是未处理的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!