vb.net文件讀取文件 net 讀取文件

vb.net 二進(jìn)制讀取文件

VB.NET打開二進(jìn)制文件用fileopen完成,打開二進(jìn)制文件的形式為:openmode.binary

成都網(wǎng)站制作、網(wǎng)站設(shè)計(jì)的開發(fā),更需要了解用戶,從用戶角度來建設(shè)網(wǎng)站,獲得較好的用戶體驗(yàn)。創(chuàng)新互聯(lián)公司多年互聯(lián)網(wǎng)經(jīng)驗(yàn),見的多,溝通容易、能幫助客戶提出的運(yùn)營建議。作為成都一家網(wǎng)絡(luò)公司,打造的就是網(wǎng)站建設(shè)產(chǎn)品直銷的概念。選擇創(chuàng)新互聯(lián)公司,不只是建站,我們把建站作為產(chǎn)品,不斷的更新、完善,讓每位來訪用戶感受到浩方產(chǎn)品的價(jià)值服務(wù)。

讀取二進(jìn)制文件用的是fileget方法,寫入二進(jìn)制文件用的是fileput方法。

應(yīng)用示例:將一批隨機(jī)數(shù)保存在一個(gè)dat文件中,然后再將其提取到文本框中。

二進(jìn)制文件的讀寫一批隨機(jī)數(shù)的存取,程序?yàn)椋?/p>

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

Dim x, i, fn As Integer

Dim s As String = ""

fn = FreeFile()

FileOpen(fn, "d:\data.dat", OpenMode.Binary)

For i = 1 To 8

x = Int(Rnd() * 100)

s = s + Str(x)

FilePut(fn, x)

Next

FileClose(fn)

TextBox1.Text = s

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim x, fn As Integer

Dim s As String = ""

fn = FreeFile()

FileOpen(fn, "d:\data.dat", OpenMode.Binary)

Do While Not EOF(fn)

FileGet(fn, x)

s = s + Str(x) + " "

Loop

FileClose(fn)

TextBox1.Text = s

End Sub

VB.net 讀取文本文件?

1、實(shí)現(xiàn)上傳按鈕方法代碼。

2、判斷圖片對象是否為空代碼。

3、取得數(shù)據(jù)庫字段 dt.Rows(0)("Pic")方法代碼。

4、字節(jié)數(shù)組轉(zhuǎn)換為Image類型方法代碼。

5、處理SQL中操作Image類型方法代碼。

6、實(shí)現(xiàn)的上傳結(jié)果。

vb.net中,讀取和寫入文件

寫入:Dim sr As New IO.StreamWriter(Application.StartupPath "/寫入的文本.txt")

sr.WriteLine("寫入的內(nèi)容") sr.Close()讀取:If (File.Exists(Application.StartupPath "/msg.txt")) Then

Dim fm As New IO.FileStream(Application.StartupPath "/讀取的文本.txt", FileMode.Open)

Dim sr As IO.StreamReader = New IO.StreamReader(fm)

Do While sr.Peek() = 0

TextBox1.Text = sr.ReadLine() (讀取文本到文本框)

Loop end if

vb.net 怎樣讀取文件

imports System.IO

讀取指定文件

'

'讀取指定文本文件

Public Function readtext(ByVal path As String)

If path = "" Then

readtext = "操作失??!"

Exit Function

End If

Try

If File.Exists(path) = True Then

Dim fs As New FileStream(path, FileMode.Open)

Dim sr As New StreamReader(fs)

Dim str As String

str = sr.ReadToEnd.ToString

sr.Close()

fs.Close()

readtext = str

Else

readtext = "操作失??!"

End If

Catch ex As Exception

readtext = "操作失?。?

End Try

End Function

'向指定文件寫入數(shù)據(jù)

Public Function writetext(ByVal path As String, ByVal opi As Integer, ByVal msg As String)

If path = "" Then

writetext = "操作失敗!"

Exit Function

End If

Dim op As FileMode

Select Case opi

Case 1

op = FileMode.Append

Case 2

op = FileMode.Create

Case Else

op = FileMode.Create

End Select

Try

If File.Exists(path) = True Then

Dim fs As New FileStream(path, op)

Dim sr As New StreamWriter(fs)

sr.WriteLine(msg)

sr.Close()

fs.Close()

writetext = "操作完成!"

Else

writetext = "操作失??!"

End If

Catch ex As Exception

writetext = "操作失?。?

End Try

End Function

VB.net 讀取文本文件

Imports?System.IO

Public?Class?Form1

Private?Sub?Form1_Load(sender?As?System.Object,?e?As?System.EventArgs)?Handles?MyBase.Load

Dim?sr?As?New?StreamReader("d:\test.csv")

Dim?arr1(),?arr2(),?arr3(),?arr4()?As?Integer

Dim?a1,?a2,?a3,?a4?As?New?ArrayList

Do?Until?sr.EndOfStream

Dim?str?As?String?=?sr.ReadLine

Dim?s()?As?String?=?str.Split(",")

a1.Add(Convert.ToInt32(s(0)))

a2.Add(Convert.ToInt32(s(1)))

a3.Add(Convert.ToInt32(s(2)))

a4.Add(Convert.ToInt32(s(3)))

ListBox1.Items.Add(s(0))

Loop

arr1?=?CType(a1.ToArray(GetType(Integer)),?Integer())

arr2?=?CType(a2.ToArray(GetType(Integer)),?Integer())

arr3?=?CType(a3.ToArray(GetType(Integer)),?Integer())

arr4?=?CType(a4.ToArray(GetType(Integer)),?Integer())

sr.Close()

End?Sub

End?Class

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é)生成績.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)容并輸出到立即窗口。

網(wǎng)站標(biāo)題:vb.net文件讀取文件 net 讀取文件
當(dāng)前地址:http://muchs.cn/article46/hjedhg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營銷、做網(wǎng)站、全網(wǎng)營銷推廣網(wǎng)站導(dǎo)航、標(biāo)簽優(yōu)化、服務(wù)器托管

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站建設(shè)網(wǎng)站維護(hù)公司