caoqinghua(生活就是互相折磨着) 在不在线?帮帮忙!
下面这段是你给我的代码用来显示远程位置的内容,现在想再麻烦你下:在里面怎么样加一段代码首先确认这个文件是否存在,在的话就执行,不在的话就提示文件不存在。谢谢啦!还有,这个贴子怎么揭贴给分啊?
Imports System.Net
Imports System.IO
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim client As New WebClient()
'读取远程文件
Dim stream As Stream = client.OpenRead( "http://www.jlhcn.cn/aa.txt ")
Dim sr As New StreamReader(stream, System.Text.Encoding.GetEncoding( "GB2312 "))
'获取数据
Dim str As String = sr.ReadToEnd()
'显示数据
Me.Label1.Text = str
End Sub
End Class
[解决办法]
Imports System.Net
Imports System.IO
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Dim client As New WebClient()
'读取远程文件
Dim stream As Stream = client.OpenRead( "http://www.jlhcn.cn/aa.txt ")
Dim sr As New StreamReader(stream, System.Text.Encoding.GetEncoding( "GB2312 "))
'获取数据
Dim str As String = sr.ReadToEnd()
'显示数据
Me.Label1.Text = str
Catch ex As Exception
MsgBox( "读取文件发生错误: " + ex.Message)
End Try
End Sub
End Class