2010年12月7日 星期二
vb.net文件操作
Imports System.IO
Imports System.Threading
Imports Enpot
Module SetTest
Private Const FileName As String = "config.txt"
Public Sub drawException(ByVal sender As Object, ByVal e As EventArgs)
Console.WriteLine("this is a wrong")
End Sub
Public Sub Main()
'Dim draw As New Draw()
'draw.Name = "hutinghu"
'draw.Money = 1000
'AddHandler draw.DrawEvent, AddressOf drawException
'draw.PlayMoney()
'Console.ReadLine()
If File.Exists(AppDomain.CurrentDomain.BaseDirectory + FileName) Then
Console.WriteLine("開始讀取文件·······")
Thread.Sleep(1000)
readFile()
Console.WriteLine("讀取完成,按Enter鍵退出·······")
Console.ReadLine()
Else
Dim file As FileStream
file = New FileStream(AppDomain.CurrentDomain.BaseDirectory + FileName, FileMode.Create, FileAccess.ReadWrite)
Console.WriteLine("文件已經創建完成!")
file.Close()
Thread.Sleep(1000)
Console.WriteLine("開始寫入文件·····")
Thread.Sleep(1000)
writeFile("Data Source=DELTA-BC6C5F378\SQLEXPRESS;Initial Catalog=hth_DB;Integrated Security=True")
' writeFile("Data Source=DELTA-BC6C5F378;Initial Catalog=_DB;Integrated Security=e")
Console.Write("寫入完成,按Enter鍵退出·······")
Console.ReadLine()
End If
End Sub
Public Sub readFile()
Dim streamRead As New StreamReader(AppDomain.CurrentDomain.BaseDirectory + FileName)
Dim strread As String = Enpot.PC.Encrypt.Decrypt(streamRead.ReadLine())
Dim temp() As String = strread.Split(";")
Dim strtemp() As String
For index As Integer = 0 To temp.Length - 1
strtemp = temp(index).Split("=")
Console.WriteLine(strtemp(1))
Next
' Console.ReadLine()
'strread = streamRead.ReadLine
'temp = strread.Split(";")
'For index As Integer = 0 To temp.Length - 1
' strtemp = temp(index).Split("=")
' Console.WriteLine(strtemp(1))
'Next
streamRead.Close()
End Sub
Public Sub writeFile(ByVal str As String)
If File.Exists(AppDomain.CurrentDomain.BaseDirectory + FileName) Then
Dim write As New StreamWriter(AppDomain.CurrentDomain.BaseDirectory + FileName)
write.WriteLine(Enpot.PC.Encrypt.Encrypt(str))
write.Close()
Console.WriteLine("文件已經寫入!按Enter鍵退出·······")
Console.ReadLine()
End If
End Sub
End Module
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言