vb.net如何关闭读取过的文件夹?你都用.net了vb.net取消读取文件,这是vb的旧语法,不推荐使用 。vb.net是面向对象的,推荐您使用
dim OpF as new io.filestream(OpenFileDialog1.FileName, IO.FileMode.Open)
...
OpF.close
或是
Using OpF as new io.filestream(OpenFileDialog1.FileName, IO.FileMode.Open)
...
End Using
但是你如果执意要用的话 , 也可以vb.net取消读取文件:
FileOpen(1, OpenFileDialog1.FileName, OpenMode.Input)
...
FileClose(1)'这里可以同时关闭多个文件号 , 文件号之间用,隔开
vb.net读写txt文件的问题这个用读写TXT的话比较繁琐vb.net取消读取文件,建议题主使用读写INI的方式 , 参考vb.net取消读取文件:
'声明INI配置文件读写API函数
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Int32, ByVal lpFileName As String) As Int32
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Int32
'定义读取配置文件函数
Public Function GetINI(ByVal Section As String, ByVal AppName As String, ByVal lpDefault As String, ByVal FileName As String) As String
Dim Str As String = LSet(Str, 256)
GetPrivateProfileString(Section, AppName, lpDefault, Str, Len(Str), FileName)
Return Microsoft.VisualBasic.Left(Str, InStr(Str, Chr(0)) - 1)
End Function
'定义写入配置文件函数
Public Function WriteINI(ByVal Section As String, ByVal AppName As String, ByVal lpDefault As String, ByVal FileName As String) As Long
WriteINI = WritePrivateProfileString(Section, AppName, lpDefault, FileName)
End Function
'定义INI文件位置
Dim path As String
path = "C:\t861239263.ini" '假设是这个文件
那么读取的时候:
TextBox1.Text = GetINI("main","v1","", path)
TextBox2.Text = GetINI("main","v2","", path)
TextBox3.Text = GetINI("main","v3","", path)
写入的时候:
WriteINI("main","v1", TextBox1.Text, path)
WriteINI("main","v2", TextBox2.Text, path)
WriteINI("main","v3", TextBox3.Text, path)
【附】INI文件的格式,范例:
[main]
v1=133233
v2=132387
v3=322333
[aaa]
abc=1
bcd=2
[bbb]
ni=wo
wo=ta
vb.net中,读取和写入文件写入:Dim sr As New IO.StreamWriter(Application.StartupPath"/写入的文本.txt")
sr.WriteLine("写入的内容")sr.Close()读?。篒f (File.Exists(Application.StartupPath"/msg.txt")) Then
Dim fm As New IO.FileStream(Application.StartupPath"/读取的文本.txt", FileMode.Open)
Dim sr As IO.StreamReader = New IO.StreamReader(fm)
Do While sr.Peek() = 0
TextBox1.Text = sr.ReadLine()(读取文本到文本框)
Loopend if
VB.net窗体设计中,如何读取.txt文件中的数据?1、新建一个标准的VB EXE工程,只有一个Form,Form上有两个按钮:Command1和Command2 。
2、双击Command1添加如下代码
Private Sub Command1_Click()
Dim strFileAs String
Dim intFileAs Integer
Dim strDataAs String
strFile = "c:\学生成绩.txt"
intFile = FreeFile
Open strFile For Input As intFile
strData = https://www.04ip.com/post/StrConv(InputB(FileLen(strFile), intFile), vbUnicode)
Debug.Print strData
Close intFile
End Sub
3、按F8开始单步调试代码,点击Command1,进入单步调试功能,
4、多次按下F8或直接按下F5运行完成,就完成了读取文本文件内容并输出到立即窗口 。
vb.net 自动读取文件名请问你是通过什么得到A文件名的?OpenFileDialog?控件吗?
推荐阅读
- sap多核的简单介绍
- 影子系统虚拟机,影子系统默认安装路径
- 微信桌面视频号,微信视频号放桌面
- 格格屋商城小程序,格格屋
- Excel同比增长怎么计算,excel中同比增长
- 现代海洋经营游戏,现代海洋经济
- linux数据库常用命令 linux数据库管理系统
- 关于jquery导入json文件格式的信息
- 监控显示无硬盘怎么弄,监控显示无硬盘怎么弄回来