本文整理汇总了VB.NET中System.IO.FileInfo.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:VB.NET FileInfo.CopyTo方法的具体用法?VB.NET FileInfo.CopyTo怎么用?VB.NET FileInfo.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.FileInfo 的用法示例。
在下文中一共展示了FileInfo.CopyTo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: Test
' 导入命名空间
Imports System.IO
Public Class Test
Public Shared Sub Main()
'Specify the directories you want to manipulate.
Dim path As String = "c:\SourceFile.txt"
Dim path2 As String = "c:\NewFile.txt"
Dim fi As FileInfo = New FileInfo(path)
Dim fi2 As FileInfo = New FileInfo(path2)
Try
Using fs As FileStream = fi.Create()
End Using
'Ensure that the target does not exist.
If File.Exists(path2) Then
fi2.Delete()
End If
'Copy the file.
fi.CopyTo(path2)
Console.WriteLine("{0} was copied to {1}.", path, path2)
Catch ioex As IOException
Console.WriteLine(ioex.Message)
End Try
End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System.IO,代码行数:30,代码来源:FileInfo.CopyTo
示例2: CopyToTest
' 导入命名空间
Imports System.IO
Public Class CopyToTest
Public Shared Sub Main()
Try
' Create a reference to a file, which might or might not exist.
' If it does not exist, it is not yet created.
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("Add as many lines as you like...")
sw.WriteLine("Add another line to the output...")
sw.Flush()
sw.Close()
' Get the information out of the file and display it.
Dim sr As New StreamReader(fi.OpenRead())
Console.WriteLine("This is the information in the first file:")
While sr.Peek() <> -1
Console.WriteLine(sr.ReadLine())
End While
' Copy this file to another file.
Dim newfi As FileInfo = fi.CopyTo("newTemp.txt")
' Get the information out of the new file and display it.
sr = New StreamReader(newfi.OpenRead())
Console.WriteLine("{0}This is the information in the second file:", Environment.NewLine)
While sr.Peek() <> -1
Console.WriteLine(sr.ReadLine())
End While
Catch e As Exception
Console.WriteLine(e.Message)
End Try
End Sub
End Class
'This code produces output similar to the following;
'results may vary based on the computer/file structure/etc.:
'
'This is the information in the first file:
'Add as many lines as you like...
'Add another line to the output...
'
'This is the information in the second file:
'Add as many lines as you like...
'Add another line to the output...
开发者ID:VB.NET开发者,项目名称:System.IO,代码行数:44,代码来源:FileInfo.CopyTo
示例3: CopyToTest
' 导入命名空间
Imports System.IO
Public Class CopyToTest
Public Shared Sub Main()
' Create a reference to a file, which might or might not exist.
' If it does not exist, it is not yet created.
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("Add as many lines as you like...")
sw.WriteLine("Add another line to the output...")
sw.Flush()
sw.Close()
' Get the information out of the file and display it.
Dim sr As New StreamReader(fi.OpenRead())
Console.WriteLine("This is the information in the first file:")
While sr.Peek() <> -1
Console.WriteLine(sr.ReadLine())
End While
' Copy this file to another file. The true parameter specifies
' that the file will be overwritten if it already exists.
Dim newfi As FileInfo = fi.CopyTo("newTemp.txt", True)
' Get the information out of the new file and display it.
sr = New StreamReader(newfi.OpenRead())
Console.WriteLine("{0}This is the information in the second file:", Environment.NewLine)
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 the information in the first file:
'Add as many lines as you like...
'Add another line to the output...
'
'This is the information in the second file:
'Add as many lines as you like...
'Add another line to the output...
'
开发者ID:VB.NET开发者,项目名称:System.IO,代码行数:42,代码来源:FileInfo.CopyTo
注:本文中的System.IO.FileInfo.CopyTo方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论