這是我第一次編寫代碼到函數文件操作。我需要將舊文件與新文件進行比較。如果舊文件名等於新文件名,則需要覆蓋(更新)。如果不相等,則創建一個新的文件名。如何以簡單和最好的方式做到這一點?c#比較2個文件 - 創建和更新函數
public void FileCreateOrOverwritten(string file)
{
try
{
if (File.Exists(file))
{
if (file == newFile)
{
//how to replace old file with a new one with new data (xml document)
//need to use filestream
}
else
{
//how to create a new file with new data (xml document)
}
}
.
.
.
}
[這](http://stackoverflow.com/a/2281769/706456)須解決它適合你。 – oleksii
你提到的XML - 考慮序列化像http://stackoverflow.com/questions/364253/how-to-deserialize-xml-document或http://stackoverflow.com/questions/4220973/c-sharp-xml-serialization-反序列化 – doctorlove