vb.net读取流的简单介绍

vb.net读取文件流

dim filename as string = "文件名" Using myfilestream As New FileStream(FileName, FileMode.Open, FileAccess.Read)

为镇原等地区用户提供了全套网页设计制作服务,及镇原网站建设行业解决方案。主营业务为成都网站建设、成都网站设计、镇原网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!

Dim data() As Byte

ReDim data(myfilestream.Length - 1)

myfilestream.Read(data, 0, myfilestream.Length)

myfilestream.Close()

' data是你要的结果,为byte(), End Using

vb.net读取流

Imports System

Imports System.IO

Imports System.TextPublic Class Form2 Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim path As String = "MyTest.txt" Try

If File.Exists(path) Then

File.Delete(path)

End If '写入流

Dim sw As StreamWriter = New StreamWriter(path)

sw.WriteLine("This")

sw.WriteLine("is some text")

sw.WriteLine("to test")

sw.WriteLine("Reading")

sw.Close()

'读取流

'Dim sr As StreamReader = New StreamReader(path) 'Do While sr.Peek() = 0

' 'This is an arbitrary size for this example.

' Dim c(5) As Char

' sr.Read(c, 0, c.Length)

' 'The output will look odd, because

' 'only five characters are read at a time.

' 'MsgBox(c)

'Loop

'sr.Close()

Catch ex As Exception

Console.WriteLine("The process failed: {0}", ex.ToString())

End Try End Sub '读取流

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim path As String = "MyTest.txt" Dim reader As StreamReader = New StreamReader(path)

Dim c(5) As Char

reader.Read(c, 0, c.Length)

MsgBox(c)

reader.Close() End Sub

End Class 解读Read(arrayChar[]()[], Int32, Int32) buffer 类型:arraySystem..::.Char[]()[]

此方法返回时,包含指定的字符数组,该数组的 index 和 (index + count - 1) 之间的值由从当前源中读取的字符替换。 index 类型:System..::.Int32

开始写入的 buffer 的索引。 count 类型:System..::.Int32

最多读取的字符数。

VB.net怎样从网络中逐个读取数据

Public Function webCaptureContent(ByVal mWebsiteUrl As String, ByVal mWebsiteType As Boolean) As String

'启动一次具体的数据采集工作,返回采集到的HTML内容:要求必须输入带://的全地址数据

On Error Resume Next

Dim Str_WebContent As String = "请输入查找网站地址."

Dim wb As WebClient = New WebClient() '//创建一个WebClient实例

If mWebsiteUrl.IndexOf("://") 0 Then

'//获取或设置用于对向 Internet 资源的请求进行身份验证的网络凭据。(可有可无)

wb.Credentials = CredentialCache.DefaultCredentials

'//从资源下载数据并返回字节数组。(加@是因为网址中间有"/"符号)

Dim pagedata As Object = wb.DownloadData(mWebsiteUrl)

'//转换字符

If mWebsiteType Then

Str_WebContent = Encoding.Default.GetString(pagedata)

Else

Str_WebContent = Encoding.UTF8.GetString(pagedata)

End If

End If

Return Str_WebContent '提取出来新闻内容,删除Body前后的多余内容,同时补充上该 Body标记,形成完整的内容 Str_WebContent '

End Function

求VB.NET读取网页内容写法

Imports System.Net

Imports System.IO

Imports System.Text.RegularExpressions

Public Class Form1

Private Sub button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

Dim stream As IO.Stream = WebRequest.Create(UrlAdress).GetResponse().GetResponseStream()

'注意urladress为你上面的网页地址。

Dim sr As StreamReader = New StreamReader(stream, System.Text.Encoding.UTF8)

Label1.Text = Regex.Match(sr.ReadToEnd, "回答采纳率").ToString

'sr。readtoend读取网页流到末尾,即使用正则表达式从网页流中提取“回答采纳率”,赋值给Label1.Text ‘没有则为空

sr.Dispose() '关闭流

End Sub'要提取什么东西用正则表达式最好

End Class


新闻名称:vb.net读取流的简单介绍
文章位置:http://lszwz.com/article/hhccdp.html

其他资讯

售后响应及时

7×24小时客服热线

数据备份

更安全、更高效、更稳定

价格公道精准

项目经理精准报价不弄虚作假

合作无风险

重合同讲信誉,无效全额退款