
<script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
請教:VB.NET中檔案寫入問題!!
本人剛接觸.NET 遇到這樣一個問題: 要把一段文字(STRING)寫入到指定檔案中,不知道用何方法,請熟悉這方面的朋友指點一下.具體判斷是 如果在指定路徑下 沒有該檔案名,則在該路徑下建立檔案. 并将上面文字寫入檔案中 儲存.
請高手幫忙 不勝感激!!
__________________________________________________________________________
Imports System.IO
Imports System.Text
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim s As String
Dim bte As Byte()
Dim myfile As New FileStream( d:/123.txt , FileMode.Create, FileAccess.Write)
s = 要儲存到檔案的文字
bte = Encoding.Default.GetBytes(s)
myfile.Write(bte, 0, bte.Length)
myfile.Close()
End Sub
End Class
__________________________________________________________________________
Dim chl As New System.IO.StreamWriter( 路徑,比如c:/123.txt , True)
chl.WriteLine( 要寫入的字元串 )
chl.Close()
__________________________________________________________________________
Dim chl As New System.IO.StreamWriter( 路徑,比如c:/123.txt , True)
chl.WriteLine( 要寫入的字元串 )
chl.Close()
__________________________________________________________________________
沒看到還要建立檔案,補充
If Not File.Exists( 路徑,比如c:/123 ) Then
File.Create( 路徑,比如c:/123 ).Close()
End If
Dim chl As New System.IO.StreamWriter( 路徑,比如c:/123.txt , True)
chl.WriteLine( 要寫入的字元串 )
chl.Close()
__________________________________________________________________________
FileOpen(1, c:/new.txt , OpenMode.Append)
PrintLine(1, 寫入第一行 )
Print(1, 寫入第二行 )
Print(1, 接在第二行後寫入 寫入第三行 )
FileClose(1)
__________________________________________________________________________
也可以用MY命名空間
__________________________________________________________________________
my.computer.filsystem.writealltext(路徑,要寫入的檔案内容,是覆寫還是追加)
__________________________________________________________________________