
<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(路径,要写入的文件内容,是覆盖还是追加)
__________________________________________________________________________