文本文件操作问题

tztz520 2004-06-21 04:25:14
怎样创建一个文本文件?
如何删除一个文本文件?
如何判断一个文本文件是否存在?
如何将一个数组的内容写到一个新建的文本文件?
谢谢
...全文
151 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
水如烟 2004-06-21
  • 打赏
  • 举报
回复
我发现楼主太懒,自己动手查查文件操作有关的类不就行了
wangchong 2004-06-21
  • 打赏
  • 举报
回复
创建文件
FileOpen(1, “文件路径和名称”, OpenMode.Output)
FileClose(1)
删除文件用 KILL

判断文件存在用DIR
AntingZ 2004-06-21
  • 打赏
  • 举报
回复
够不够,不够我再多拷贝一写来?
AntingZ 2004-06-21
  • 打赏
  • 举报
回复
代码:将文本写入文件 (Visual Basic)请参见
代码:读取文本文件 (Visual Basic) | 通过 StreamReader 和 StreamWriter 类进行文件访问 | StreamWriter 类 | 系统输入/输出示例主题 此示例使用 StreamWriter 类的 WriteLine 方法将字符串写入一个文本文件中。
示例
Dim file As New System.IO.StreamWriter("c:\test.txt")
file.WriteLine("Here is the first line.")
file.Close()


代码:确定文件夹是否存在 (Visual Basic)请参见
代码:创建文件夹 (Visual Basic) | System.IO 命名空间 | Directory.Exists 方法 | 代码访问安全性基础知识 | 系统输入/输出示例主题 此示例设置 Boolean 变量,指示指定的文件夹是否存在。
示例
Dim exists As Boolean
exists = System.IO.Directory.Exists("c:\ExistingFolderName")


代码:获取有关文件的信息 (Visual Basic)请参见
演练:与 Visual Basic .NET 中的文件和文件夹交互 | FileInfo 类 | 系统输入/输出示例主题 此示例确定文件 MyFile 的创建时间、目录、全名和文件大小,并在 MsgBox 中显示结果。
示例
Private Sub GetFileInfo()
Dim fileName as String = "C:\Test.txt"
Dim fileData As String
Dim fileDetails As System.IO.FileInfo = New System.IO.FileInfo(MyFile)

With fileDetails
fileData = "File was created at: " & _
.CreationTime.ToLongTimeString & vbCrLf & _
"File Directory is: " & _
.Directory.ToString & vbCrLf & _
"Full name is: " & _
.FullName & vbCrLf & _
"File Size is: " & _
.Length.ToString &vbCrLf
End With

MsgBox(fileData)
End Sub

代码:读取文本文件 (Visual Basic)请参见
代码:将文本写入文件 (Visual Basic) | 通过 StreamReader 和 StreamWriter 类进行文件访问 | StreamWriter 类 | Visual Basic 代码示例主题 此示例使用 StreamReader 类的 ReadToEnd 方法将文本文件的内容读入到字符串中。
示例
Dim file As New System.IO.StreamReader("c:\test.txt")
Dim words As String = file.ReadToEnd()
file.Close()

此示例在计算机上创建两个新文件夹。
示例
System.IO.Directory.CreateDirectory("c:\NewFolder")
System.IO.Directory.CreateDirectory("c:\NewFolder\NewSubFolder")


AntingZ 2004-06-21
  • 打赏
  • 举报
回复
看 MSDN

代码:创建文件 (Visual Basic)请参见
System.IO 命名空间 | File.Create 方法 | 通过部分受信任的代码使用库 | 代码访问安全性基础知识 | 系统输入/输出示例主题 此示例在指定的路径创建空文本文件。
示例
Dim file As System.IO.FileStream
file = System.IO.File.Create("c:\test.txt")


代码:复制文件 (Visual Basic)请参见
演练:在 Visual Basic .NET 中操作文件和文件夹 | File.Copy 方法 | 系统输入/输出示例主题 此示例将文件 Source.txt 复制到第二个文件 Copy.txt。
示例
Private Sub FileCopier
Dim Source As String = "C:\Source.txt"
Dim Destination As String = "C:\Copy.txt"
System.IO.File.Copy(Source, Destination, True)
End Sub


代码:确定文件是否存在 (Visual Basic)请参见
代码:确定文件夹是否存在 (Visual Basic) | System.IO 命名空间 | File.Exists 方法 | 系统输入/输出示例主题 此示例设置 Boolean 变量,指示指定的文件是否存在。
示例
Dim exists As Boolean
exists = System.IO.File.Exists("c:\ExistingFileName")
tztz520 2004-06-21
  • 打赏
  • 举报
回复
要代码,唔该

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧