Window mobile读取text文件的内容
2010-08-22 13:10:00 来源:WEB开发网读取utf8格式的文本
Imports System
Imports System.IO
Imports System.Text
Public Class Form1
Dim lujingapp As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strutf8 As String
Dim myreader As StreamReader
myreader = System.IO.File.OpenText(lujingapp & "test.txt")
strutf8 = myreader.ReadToEnd
TextBox1.Text = strutf8
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
lujingapp = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.GetName.CodeBase)
lujingapp = lujingapp & "\" '获取当前路径
End Sub
End Class
读取普通的文本
Imports System
Imports System.IO
Imports System.Text
Public Class Form1
Dim lujingapp As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim str As String
Dim myfilestream As FileStream
Dim myreader As StreamReader
myfilestream = System.IO.File.OpenRead(lujingapp & "test.txt")
myreader = New StreamReader(myfilestream, Encoding.Default)
str = myreader.ReadToEnd
TextBox1.Text = str
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
lujingapp = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.GetName.CodeBase)
lujingapp = lujingapp & "\" '获取当前路径
End Sub
End Class
赞助商链接