标题:vb.net中FileInfo的用法是什么?
只看楼主
heying
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2006-8-31
 问题点数:0 回复次数:5 
vb.net中FileInfo的用法是什么?
vb.net中FileInfo的用法是什么?

能举个例子具体说明一下吗?
搜索更多相关主题的帖子: net中 FileInfo 用法 例子 
2006-09-01 17:17
chenjin145
Rank: 1
等 级:禁止访问
帖 子:3922
专家分:0
注 册:2006-7-12
得分:0 
[CODE]

Public Shared Sub Main()
Dim path As String = "c:\temp\MyTest.txt"
Dim fi1 As FileInfo = New FileInfo(path)

If fi1.Exists = False Then
'Create a file to write to.
Dim sw As StreamWriter = fi1.CreateText()
sw.WriteLine("Hello")
sw.WriteLine("And")
sw.WriteLine("Welcome")
sw.Flush()
sw.Close()
End If

'Open the file to read from.
Dim sr As StreamReader = fi1.OpenText()

Do While sr.Peek() >= 0
Console.WriteLine(sr.ReadLine())
Loop

Try
Dim path2 As String = path + "temp"
Dim fi2 As FileInfo = New FileInfo(path2)

'Ensure that the target does not exist.
fi2.Delete()

'Copy the file.
fi1.CopyTo(path2)
Console.WriteLine("{0} was copied to {1}.", path, path2)

'Delete the newly created file.
fi2.Delete()
Console.WriteLine("{0} was successfully deleted.", path2)

Catch e As Exception
Console.WriteLine("The process failed: {0}", e.ToString())
End Try
End Sub


[/CODE]

[此贴子已经被作者于2006-9-1 17:19:44编辑过]


[url=javascript:alert(1);] [div]fdgfdgfdg\" on\"[/div] [/url]
2006-09-01 17:18
wfscyl
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2006-10-3
得分:0 
还可以用来做文件默认的打开方式
2006-10-13 10:22
梓风
Rank: 2
等 级:新手上路
威 望:4
帖 子:181
专家分:0
注 册:2006-10-22
得分:0 
FileInfo 类用于典型的操作,如复制、移动、重命名、创建、打开、删除和追加到文件。


等待相逢
2006-10-28 20:44
bingche
Rank: 1
等 级:新手上路
帖 子:49
专家分:8
注 册:2006-11-7
得分:0 

我试了,怎么出现错误,在Dim fi1 As FileInfo = New FileInfo(path)位置
提示需要类型。


2006-11-08 09:53
bingche
Rank: 1
等 级:新手上路
帖 子:49
专家分:8
注 册:2006-11-7
得分:0 

2006-11-08 09:53



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-87467-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.112906 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved