本文整理汇总了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