file.Replace问题 大虾们帮忙解决下 为什么会找不到指定文件啊
using System;using System.IO;
namespace FileSystemExample
{
class FileExample
{
public static void Main()
{
try
{
string OriginalFile = "test.xml";
string FileToReplace = "test2.xml";
string BackUpOfFileToReplace = "test2.xml.bac";
Console.WriteLine("Move the contents of " + OriginalFile + " into " + FileToReplace + ", delete " + OriginalFile +
", and create a backup of " + FileToReplace + ".");
// Replace the file.
ReplaceFile(OriginalFile, FileToReplace, BackUpOfFileToReplace);
Console.WriteLine("Done");
}
catch (Exception e)
{
Console.WriteLine(e);
}
Console.ReadLine();
}
// Move a file into another file, delete the original, and create a backup of the replaced file.
public static void ReplaceFile(string FileToMoveAndDelete, string FileToReplace, string BackupOfFileToReplace)
{
// Create a new FileInfo object.
FileInfo fInfo = new FileInfo(FileToMoveAndDelete);
// replace the file.
fInfo.Replace(FileToReplace, BackupOfFileToReplace, false);
}
}
}
--------------------编程问答-------------------- 想实现什么功能
File.Move
--------------------编程问答-------------------- 用一个空文档覆盖原来的文档 达到删除文档内容的效果
补充:.NET技术 , C#