大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
Public Class Form1
浉河网站建设公司创新互联建站,浉河网站设计制作,有大型网站制作公司丰富经验。已为浉河上千提供企业网站建设服务。企业网站搭建\外贸网站制作要多少钱,请找那个售后服务好的浉河做网站的公司定做!
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
最简单的方法 还有很多方法 自己研究吧亲 希望能帮到你
设计一个窗口,添加一个名为textBox1的System.Windows.Forms.TextBox,
添加一个名为button1的System.Windows.Forms.Button。
为button1的单击事件添加如下处理函数:
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当前写入的文件内容. 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("文章标题").value ,rs.filds("文章").value rs.movenext loop '关闭记录集等 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
'取得存储的文本
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
'存储文本
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
'取得存储路径
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个文本框,设置成多行,2个按钮,在文本框1里随便输入若干文字,可以多行,单击按钮1,保存到文件。然后单击按钮2,把刚才写入的文件读到文本框2里。
代码如下:
'写文本文件
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'创建(写入)一个文本文件
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
'读取一个文本文件
Dim MyReader As New System.IO.StreamReader(Application.StartupPath "\Ssk.txt", System.Text.Encoding.UTF8)
TextBox2.Text = MyReader.ReadToEnd()
MyReader.Close()
End Sub
气斜射入水或其他介质,折射光线与入射光线法线在