首先引入System.IO命名空間
讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來(lái)自于我們對(duì)這個(gè)行業(yè)的熱愛(ài)。我們立志把好的技術(shù)通過(guò)有效、簡(jiǎn)單的方式提供給客戶,將通過(guò)不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長(zhǎng)期合作伙伴,公司提供的服務(wù)項(xiàng)目有:空間域名、雅安服務(wù)器托管、營(yíng)銷軟件、網(wǎng)站建設(shè)、滄源網(wǎng)站維護(hù)、網(wǎng)站推廣。
Imports System.IO
然后使用文件流來(lái)讀入數(shù)組:
Dim bytes() As Byte
Using fs As New FileStream(文件路徑,FileMode.Open)
ReDim bytes(fs.Length-1)
fs.Read(bytes,0,fs.Length)
fs.Close()
End Using
這樣bytes就是整個(gè)文件的所有字節(jié)了
從字節(jié)生成Image:
Dim img As Image = Image.FromStream(New MemoryStream(bytes))
img就是圖片了
為什么非要存成TXT文件呢?最好的辦法是將你的這些數(shù)據(jù)存放在DataSet對(duì)象里,然后用DataSet對(duì)象的WriteXML方法寫(xiě)入文件。下次讀取時(shí),使用該對(duì)象的ReadXML方法就可以取回存在文件中的數(shù)據(jù)了。你想增、刪、編輯都可以,很方便的!如果非要生成TXT文件,可以在DataSet對(duì)象順序讀取數(shù)據(jù),然后再生成想要的TXT文件。你也用不著去追究IO流的操作了。
System.IO.StreamReader objread = new System.IO.StreamReader(path);
System.IO.Stream stream = objread.BaseStream;
objread.Close();
所有信息全在stream 里了
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 '寫(xiě)入流
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[]()[]
此方法返回時(shí),包含指定的字符數(shù)組,該數(shù)組的 index 和 (index + count - 1) 之間的值由從當(dāng)前源中讀取的字符替換。 index 類型:System..::.Int32
開(kāi)始寫(xiě)入的 buffer 的索引。 count 類型:System..::.Int32
最多讀取的字符數(shù)。
網(wǎng)站標(biāo)題:vb點(diǎn)虐
io流的簡(jiǎn)單介紹
文章網(wǎng)址:http://jinyejixie.com/article34/ddicpse.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供關(guān)鍵詞優(yōu)化、外貿(mào)網(wǎng)站建設(shè)、移動(dòng)網(wǎng)站建設(shè)、App開(kāi)發(fā)、網(wǎng)站策劃、電子商務(wù)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)