本文整理匯總了VB.NET中System.CodeDom.Compiler.TempFileCollection類的典型用法代碼示例。如果您正苦於以下問題:VB.NET TempFileCollection類的具體用法?VB.NET TempFileCollection怎麽用?VB.NET TempFileCollection使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了TempFileCollection類的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Program
' 導入命名空間
Imports System.CodeDom.Compiler
Imports System.IO
Class Program
Shared Sub Main(ByVal args() As String)
' Create a directory in the current working directory.
Directory.CreateDirectory("testDir")
Dim tfc As New TempFileCollection("testDir", False)
' Returns the file name relative to the current working directory.
Dim fileName As String = tfc.AddExtension("txt")
Console.WriteLine(fileName)
' Name a file in the test directory.
Dim file2Name As String = "testDir\test.txt"
' Add the file to the temp directory and indicate it is to be kept.
tfc.AddFile(file2Name, True)
Console.WriteLine(tfc.Count)
' Create and use the test files.
Dim fs1 As FileStream = File.OpenWrite(fileName)
Dim fs2 As FileStream = File.OpenWrite(file2Name)
Dim sw1 As New StreamWriter(fs1)
Dim sw2 As New StreamWriter(fs2)
sw1.WriteLine("Test string")
sw2.WriteLine("Test string")
sw1.Close()
sw2.Close()
tfc.Delete()
Console.WriteLine(tfc.Count)
Try
' This call should succeed.
File.OpenRead(file2Name)
' This call should fail.
File.OpenRead(fileName)
Catch e As FileNotFoundException
Console.WriteLine(e.Message)
End Try
End Sub
End Class