vb.net文件操作教材 vbnet filestream

vb.net对文件的操作,在线等Dim txtStr As String = "F:\te.txt" 'txt文件路径
Dim endname As String = "doc" '文件类型
Dim folderStr As String = "e:\file\我的文档\毕业设计" '目录位置
Dim str() As String = IO.Directory.GetFiles(folderStr)
For i = 0 To str.Length - 1
Dim itendname As String = Strings.Right(str(i), str(i).Length - Strings.InStrRev(str(i), "."))
Dim strs As String = ""
If itendname = endname Then
strs= str(i)vbCrLf
End If
IO.File.AppendAllText(txtStr, strs)
Next
vb.net 文件夹操作【vb.net文件操作教材 vbnet filestream】vb.net使用控件FolderBrowserDialog1,在程序中:
'设置对话框中在树视图控件上显示的说明文本
Me.FolderBrowserDialog1.Description
=
"请选择输出报表所在路径:"
'设置从其开始浏览的根文件夹
Me.FolderBrowserDialog1.SelectedPath
=
"c:\"
If
Me.FolderBrowserDialog1.ShowDialog()
=
DialogResult.OK
Then
'取得全路径(包含文件名)
reportPath1
=
System.IO.Path.GetFullPath(Me.FolderBrowserDialog1.SelectedPath)
'设定text显示文件名
txtReport1.Text
=
reportPath1
setReportList()
End
If
在setReportList()中针对你所需要的文件进行操作等
vb.net2010怎样操作文本文件1.使用app.config文件
2.使用xml
3.使用ini
4.使用数据库等都可以
如何使用VB.NET FileInfo类对文件操作在网上收到一些关于文件操作的列子,现在和大家分享一下,以下的示例代码将向您展示如何使用VB.NET FileInfo来拷贝、移动和删除文件,以及如何使用DirectoryInfo来移动和删除文件夹 。(注意:为了运行这些示例,您需要将这条语句:Imports System.IO , 添加到您的表单或模块的最顶部 。)
VB.NET FileInfo示例 拷贝一个文件 1. Dim fFile1 As New FileInfo("C:abc1.txt")2.3. fFile1.CopyTo("C:abc2.txt", True)4. 我们将fFile1变量定义为一个FileInfo对象并设定它指向文件系统中的一个目录,为了拷贝一个文件,我们使用FileInfo对象中的CopyTo方法并指明我们计划要拷贝的目标文件的全名 。移动一个文件 1. Dim fFile1 As New FileInfo("C:abc1.txt")2.3. fFile1.MoveTo("C:abc3.txt")4. 我们将fFile1变量定义为一个FileInfo对象并设定它指向文件系统中的一个目录,为了拷贝一个文件,我们使用FileInfo对象中的CopyTo方法并指明我们计划要移动的目标文件的全名 。删除一个文件 1. Dim fFile1 As New FileInfo("C:abc1.txt")2.3. fFile1.Delete()4. 我们将fFile1变量定义为一个FileInfo对象并设定它指向文件系统中的一个目录 , 为了删除一个文件 , 我们使用FileInfo对象中的Delete方法 。VB.NET FileInfo DirectoryInfo示例 移动一个文件夹 1. Dim dDir1 As New DirectoryInfo("C:Folder1")2.3. dDir1.MoveTo("C:Folder2")4. 我们将dDir1变量定义为一个DirectoryInfo对象并设定它指向文件系统中的一个目录 , 为了移动一个文件夹,我们使用DirectoryInfo对象的MoveTo方法,并指明我们所移动的文件夹的完整目标路径 。删除一个文件夹 1. Dim dDir1 As New DirectoryInfo("C:Folder1")2.3. dDir1.Delete()4. 我们将dDir1变量定义为一个DirectoryInfo对象并设定它指向文件系统中的一个目录,为了删除一个文件夹,我们使用DirectoryInfo对象的Delete方法 。) 作者:未知 来源:网络
VB.NET里的文件操作我想你可以这样考虑...
插入\删除\修改都可以基于读,写实现
比较简单的是删除操作(我理解你想要清空内容),直接写入空字符即可
接下来是修改
首先你需要修改的文件以文本形式读到界面(Web)的文本框或者DIV(加入属性 contenteditable="true" )中
修改完成后,再将内容提交保存到刚才打开的文本文件即可
实现了修改,普通插入不再是难事.
vb.net 怎样读取文件imports System.IO
读取指定文件
'
'读取指定文本文件
Public Function readtext(ByVal path As String)
If path = "" Then
readtext = "操作失败!"
Exit Function
End If
Try
If File.Exists(path) = True Then
Dim fs As New FileStream(path, FileMode.Open)
Dim sr As New StreamReader(fs)
Dim str As String
str = sr.ReadToEnd.ToString
sr.Close()
fs.Close()
readtext = str
Else
readtext = "操作失败!"
End If
Catch ex As Exception
readtext = "操作失败!"
End Try
End Function
'向指定文件写入数据
Public Function writetext(ByVal path As String, ByVal opi As Integer, ByVal msg As String)
If path = "" Then
writetext = "操作失败!"
Exit Function
End If
Dim op As FileMode
Select Case opi
Case 1
op = FileMode.Append
Case 2
op = FileMode.Create
Case Else
op = FileMode.Create
End Select
Try
If File.Exists(path) = True Then
Dim fs As New FileStream(path, op)
Dim sr As New StreamWriter(fs)
sr.WriteLine(msg)
sr.Close()
fs.Close()
writetext = "操作完成!"
Else
writetext = "操作失败!"
End If
Catch ex As Exception
writetext = "操作失败!"
End Try
End Function
vb.net文件操作教材的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于vbnet filestream、vb.net文件操作教材的信息别忘了在本站进行查找喔 。

    推荐阅读