有一些日誌文件被某些系統服務使用。我想讓我的程序讀取該文件。無法讀取文件,但可以將其複製到C#中
如果我使用System.IO.File.ReadAllText()
我得到System.IO.IOException
與The process cannot access the file 'X' because it is being used by another process.
消息。然而,如果我打電話給System.IO.File.Copy()
,我可以將該文件複製到臨時文件中並讀取臨時文件。
這有點奇怪。如果我可以複製文件,爲什麼我不能打開它閱讀?
是否可以只讀取該文件而不先複製它?