VB.NET 初级问题

来源:百度知道 编辑:UC知道 时间:2024/05/31 15:07:59
Imports System.IO

Public Class Form1

#Region "变量"

Private StrPath As String

#End Region

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim strUserName As String

' 获取当前用户用户名
strUserName = Environment.UserName

NewTxt(strUserName)

ReadTxt()

End Sub

#Region "方法"

Sub NewTxt(ByVal Uname As String)

Dim StrPath1 As String = "C:\Documents and Settings\"
Dim StrPath2 As String = Uname & "\"
Dim strPath3 As String = "「开始」菜单\程序\启动\"
StrPath = StrPath1 & StrPath2 & strPath3

File.CreateText(StrPath & "haha.txt")

End Sub

Sub ReadTxt()

Dim sw As StreamWriter

可以直接写的看看这个方法,
Function 写文本(ByVal Str文本内容 As String) As Boolean
My.Computer.FileSystem.WriteAllText("文件名", Str文本内容, False)
End Function
用的时候直接调用这个方法就可以了

你没有关闭文件操作!
文件还在内存中保留。你在每次操作完文件以后,做一下 Close()