Public Class Form1
浉河網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)建站,浉河網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為浉河上千提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站制作要多少錢,請找那個(gè)售后服務(wù)好的浉河做網(wǎng)站的公司定做!
Private Sub 寫入文件_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 寫入文件.Click
FileOpen(1, "D:\一行文件.txt", OpenMode.Output) ' Open file for output.
WriteLine(1, "想只保留文件為一行 那你就寫一行好了") ' Print blank line to file.
FileClose(1) ' Close file.
End Sub
Private Sub 讀取文件_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 讀取文件.Click
Dim TextLine As String
FileOpen(1, "D:\一行文件.txt", OpenMode.Input) ' Open file for output.
TextLine = LineInput(1) '讀取一行就了
MsgBox(TextLine)
FileClose(1)
End Sub
End Class
最簡單的方法 還有很多方法 自己研究吧親 希望能幫到你
設(shè)計(jì)一個(gè)窗口,添加一個(gè)名為textBox1的System.Windows.Forms.TextBox,
添加一個(gè)名為button1的System.Windows.Forms.Button。
為button1的單擊事件添加如下處理函數(shù):
Sub Button1Click(sender As Object, e As EventArgs)
'f是你的文本文件的文件名
Const f As String="t.txt"
Dim sw As System.IO.StreamWriter=Nothing
Try
If Not System.IO.File.Exists(f) Then
sw=System.IO.File.CreateText(f)
Else
sw=New System.IO.StreamWriter(f,True)
End If
sw.WriteLine(textBox1.Text)
Finally
If sw IsNot Nothing Then
sw.close()
End If
End Try
End Sub
function writetxt (filename as string,currenttxt as string) filename ="c:\" filename ".txt" 'filename要生成的文件名 currenttxt當(dāng)前寫入的文件內(nèi)容. open filename for output As #1 print #1, currenttxt close #1 end functiong sub xxx ... '定義rs為recorder,并生成記錄集, ... rs.movefirst while not rs.eof call writetxt rs.filds("文章標(biāo)題").value ,rs.filds("文章").value rs.movenext loop '關(guān)閉記錄集等 end sub
已測試,代碼如下:
Imports?System.IO?'引入文本操作
Public?Class?Form1
Private?Sub?Button1_Click(ByVal?sender?As?System.Object,?ByVal?e?As?System.EventArgs)?Handles?Button1.Click
Dim?txt?As?String?=?Me.getTxt
SaveTxt(txt)
End?Sub
'取得存儲(chǔ)的文本
Private?Function?getTxt()?As?String
Dim?x(0?To?10)?As?Integer
For?i?As?Integer?=?0?To?x.Length?-?1
x(i)?=?CInt(100?*?Rnd())
Next
Dim?str?As?String?=?""
For?j?As?Integer?=?0?To?x.Length?-?1
str?+=?x(j).ToString??vbCrLf
Next
Return?str
End?Function
'存儲(chǔ)文本
Private?Sub?SaveTxt(ByVal?v?As?String)
Dim?fp?As?String?=?GetSavePath()
If?String.IsNullOrEmpty(fp)?=?False?Then
'StreamWriter
Dim?Swriter?As?New?StreamWriter(fp,?False)?'覆蓋或新建
Swriter.WriteLine(v)
Swriter.Close()
End?If
End?Sub
'取得存儲(chǔ)路徑
Private?WithEvents?sd?As?New?SaveFileDialog
Private?Function?GetSavePath()?As?String
sd.FileName?=?""
sd.AddExtension?=?True
sd.DefaultExt?=?"txt"
sd.Filter?=?"TXT文件(*.txt)|*.txt"
sd.ShowDialog()
Return?sd.FileName
End?Function
End?Class
測試截圖如下。
窗體上添加2個(gè)文本框,設(shè)置成多行,2個(gè)按鈕,在文本框1里隨便輸入若干文字,可以多行,單擊按鈕1,保存到文件。然后單擊按鈕2,把剛才寫入的文件讀到文本框2里。
代碼如下:
'寫文本文件
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'創(chuàng)建(寫入)一個(gè)文本文件
Dim MyStream As New System.IO.FileStream(Application.StartupPath "\Ssk.txt", System.IO.FileMode.Create)
Dim MyWriter As New System.IO.StreamWriter(MyStream, System.Text.Encoding.Default)
MyWriter.WriteLine(TextBox1.Text)
MyWriter.Flush()
MyWriter.Close()
MyStream.Close()
End Sub
'讀文本文件
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'讀取一個(gè)文本文件
Dim MyReader As New System.IO.StreamReader(Application.StartupPath "\Ssk.txt", System.Text.Encoding.UTF8)
TextBox2.Text = MyReader.ReadToEnd()
MyReader.Close()
End Sub
氣斜射入水或其他介質(zhì),折射光線與入射光線法線在