欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

關(guān)于vb.nettxt的信息

請(qǐng)教在VB.net中如何將數(shù)據(jù)寫入txt文件、再?gòu)膖xt文件讀出?

軟糖來告訴你吧。

創(chuàng)新互聯(lián)專注于龍湖網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠(chéng)為您提供龍湖營(yíng)銷型網(wǎng)站建設(shè),龍湖網(wǎng)站制作、龍湖網(wǎng)頁設(shè)計(jì)、龍湖網(wǎng)站官網(wǎng)定制、成都微信小程序服務(wù),打造龍湖網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供龍湖網(wǎng)站排名全網(wǎng)營(yíng)銷落地服務(wù)。

VB.net中讀寫文件主要使用System.IO命名空間。

① 使用 File.ReadAllText 讀取

Dim s As String = System.IO.File.ReadAllText("C:\a.txt")

② 使用 StreamReader 讀取,注意編碼格式和寫入的編碼保持一致。

Dim sr As StreamReader = New StreamReader("C:\a.txt", System.Text.Encoding.UTF8)

Dim s As String = sr.ReadToEnd()

sr.Close()

③ 使用 File.WriteAllText 寫入,會(huì)覆蓋同名的文件。

Dim 要寫的內(nèi)容 As String = ""

File.WriteAllText(文件路徑, 要寫的內(nèi)容, System.Text.Encoding.UTF8)

④ 使用 StreamWriter 寫入。

Dim sw As System.IO.StreamWriter = New System.IO.StreamWriter("C:\a.txt", False, System.Text.Encoding.UTF8)

sw.WriteLine(TextTB.Text)

sw.Close()

⑤ 使用 StreamWriter 追加寫入。

將上面代碼的第二個(gè)參數(shù)False改為True。

◆ 滿意請(qǐng)采納,謝謝 ◆

VB.NET讀取TXT文件數(shù)據(jù)保存為數(shù)組

VB.NET編程讀取txt文本文檔中的數(shù)據(jù),并把數(shù)據(jù)保存為數(shù)組,代碼如下:

'寫配件文件

Private?Sub?saveIni(ByVal?filePath?As?String,?ByVal?str?As?String)

Dim?sw?As?StreamWriter?=?New?StreamWriter(filePath,?True)?'true是指以追加的方式打開指定文件

sw.WriteLine(str)

sw.Flush()

sw.Close()

sw?=?Nothing

End?Sub

'讀配件文件

Private?Function?readIni(ByVal?filePath?As?String)

Dim?iniDt?As?New?DataTable

iniDt.Columns.Add("text")

iniDt.Columns.Add("value")

Try

Dim?sr?As?StreamReader?=?New?StreamReader(filePath,?System.Text.Encoding.Default)

Dim?line?As?String?=?""

While?Not?sr.EndOfStream

Dim?str?=?sr.ReadLine()'讀取當(dāng)前行

iniDt.Rows.Add(New?String()?{

str(0),

str(1)

})

End?While

sr.Close()

sr?=?Nothing

Catch?ex?As?Exception

End?Try

Return?iniDt

End?Function

VB.net窗體設(shè)計(jì)中,如何讀取.txt文件中的數(shù)據(jù)?

1、新建一個(gè)標(biāo)準(zhǔn)的VB EXE工程,只有一個(gè)Form,F(xiàn)orm上有兩個(gè)按鈕:Command1和Command2。

2、雙擊Command1添加如下代碼

Private Sub Command1_Click()

Dim strFile? ? ?As String

Dim intFile? ? ?As Integer

Dim strData? ? ?As String

strFile = "c:\學(xué)生成績(jī).txt"

intFile = FreeFile

Open strFile For Input As intFile

strData = StrConv(InputB(FileLen(strFile), intFile), vbUnicode)

Debug.Print strData

Close intFile

End Sub

3、按F8開始單步調(diào)試代碼,點(diǎn)擊Command1,進(jìn)入單步調(diào)試功能,

4、多次按下F8或直接按下F5運(yùn)行完成,就完成了讀取文本文件內(nèi)容并輸出到立即窗口。

文章名稱:關(guān)于vb.nettxt的信息
分享URL:http://chinadenli.net/article14/dogeige.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)網(wǎng)頁設(shè)計(jì)公司、定制開發(fā)做網(wǎng)站搜索引擎優(yōu)化、企業(yè)網(wǎng)站制作

廣告

聲明:本網(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í)需注明來源: 創(chuàng)新互聯(lián)

手機(jī)網(wǎng)站建設(shè)