function Newfile as fileinfo

在石嘴山等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都做網(wǎng)站、成都網(wǎng)站制作 網(wǎng)站設(shè)計(jì)制作按需策劃設(shè)計(jì),公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),成都品牌網(wǎng)站建設(shè),網(wǎng)絡(luò)營銷推廣,外貿(mào)營銷網(wǎng)站建設(shè),石嘴山網(wǎng)站建設(shè)費(fèi)用合理。
Dim dic As New System.IO.DirectoryInfo("C:\Users\Q\Desktop\數(shù)據(jù)")
Dim files = dic.GetFiles.OrderByDescending(Function(s) s.CreationTime)
if files.
return files.first
end function
注意引入 system.linq
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
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)容并輸出到立即窗口。
軟糖來告訴你吧。
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雖也有input語句,但一次只能讀取到一個(gè)變量中,可以用TextFieldParser類代替,但似乎沒以前的方便。不過比以前的更靈活。寫入文件Write還是可以用,在Microsoft.VisualBasic.FileIO中。
Private?Sub?Button1_Click(ByVal?sender?As?System.Object,?ByVal?e?As?System.EventArgs)?Handles?Button1.Click
Dim?fileName?As?String?=?"E:\User?Documents\Master\My?Documents\電子閱讀\股票\table2.csv"
Using?Recrods?As?New?Microsoft.VisualBasic.FileIO.TextFieldParser(fileName)?'建立TextFieldParser對(duì)象
'MyReader.TextFieldType?=?FieldType.Delimited
Recrods.SetDelimiters(",")?'把字段分隔符設(shè)置為","
Dim?curRow()?As?String
Do?Until?Recrods.EndOfData
curRow?=?Recrods.ReadFields()?'讀取記錄行,返回字符串?dāng)?shù)組,所以不同字段類型需要自己轉(zhuǎn)換。
Debug.Print(Join(curRow,?vbTab))
Loop
End?Using
End?Sub
新聞標(biāo)題:vb.net數(shù)值文件 vbnet數(shù)據(jù)庫編程例子
本文來源:http://chinadenli.net/article40/hghoho.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)公司、外貿(mào)建站、網(wǎng)站設(shè)計(jì)公司、動(dòng)態(tài)網(wǎng)站、網(wǎng)站設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)