继续上一节的学习。
创建一个空文件:
Private Sub btnCreateFile_Click(sender As Object,e As EventArgs) Handles btnCreateFile.Click If File.Exists("d:\bb.jpg") Then txtFileInfo.Text = "该文件已经存在" Else File.Create("d:\bb.jpg") txtFileInfo.Text = "创建文件成功" End If End Sub
Private Sub btnDelFile_Click(sender As Object,e As EventArgs) Handles btnDelFile.Click If File.Exists("d:\bb.jpg") Then Try File.Delete("d:\bb.jpg") txtFileInfo.Text = "该文件已经删除" Catch ex As Exception txtFileInfo.Text = "删除文件时发生错误:" & ex.Message End Try Else txtFileInfo.Text = "该文件不存在" End If End Sub
移动文件:
Private Sub btnMoveFile_Click(sender As Object,e As EventArgs) Handles btnMoveFile.Click If File.Exists("d:\bb.jpg") Then Try File.Move("d:\bb.jpg","e:\bb.jpg") txtFileInfo.Text = "文件已经移动" Catch ex As Exception txtFileInfo.Text = "移动文件时发生错误," & ex.Message End Try Else txtFileInfo.Text = "文件不存在" End If End Sub
学习更多vb.net知识,请参看 vb.net 教程 目录