本文整理匯總了VB.NET中System.IO.FileInfo.FileInfo構造函數的典型用法代碼示例。如果您正苦於以下問題:VB.NET FileInfo構造函數的具體用法?VB.NET FileInfo怎麽用?VB.NET FileInfo使用的例子?那麽, 這裏精選的構造函數代碼示例或許可以為您提供幫助。您也可以進一步了解該構造函數所在類System.IO.FileInfo
的用法示例。
在下文中一共展示了FileInfo構造函數的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Test
' 導入命名空間
Imports System.IO
Class Test
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
End Class
'This code produces output similar to the following;
'results may vary based on the computer/file structure/etc.:
'
'Hello
'And
'Welcome
'c:\MyTest.txt was copied to c:\MyTest.txttemp.
'c:\MyTest.txttemp was successfully deleted.
示例2: FileInfoMainTest
' 導入命名空間
Imports System.IO
Public Class FileInfoMainTest
Public Shared Sub Main()
' Open an existing file, or create a new one.
Dim fi As New FileInfo("temp.txt")
' Create a writer, ready to add entries to the file.
Dim sw As StreamWriter = fi.AppendText()
sw.WriteLine("This is a new entry to add to the file")
sw.WriteLine("This is yet another line to add...")
sw.Flush()
sw.Close()
Dim sr As New StreamReader(fi.OpenRead())
' Get the information out of the file and display it.
While sr.Peek() <> -1
Console.WriteLine(sr.ReadLine())
End While
End Sub
End Class
'This code produces output similar to the following;
'results may vary based on the computer/file structure/etc.:
'
'This is a new entry to add to the file
'This is yet another line to add...