簡體   English   中英

File.ReadAllText和File.WriteAllText之后

[英]File.ReadAllText and after File.WriteAllText

我的問題是,當我運行此代碼時,它在“ File.WriteAllText”行的procedure.pas上告訴我,另一個程序正在使用它。

script = File.ReadAllText(Application.StartupPath + "\\Procedure.pas");
decryptedstring = Crypter.Decrypt(script, sSecretKey);

decryptedstring = decryptedstring.Replace("_" + Firma + "_", "_" + txtFirma.Text + "_");
decryptedstring = decryptedstring.Replace("_" + DonemNo + "_", "_" + txtDonemNo.Text + "_");
decryptedstring = decryptedstring.Replace("FIRMNR=" + Firma + " ", "FIRMNR=" + txtFirma.Text + " ");
encryptedstring = Crypter.Encrypt(decryptedstring, sSecretKey);
File.WriteAllText(Application.StartupPath + "\\Procedure.pas", encryptedstring);

可能正在使用共享鎖打開正在寫入的文件,該共享鎖允許其他進程讀取數據但不允許寫入。 因此,當您打開文件進行寫入時,盡管該文件始終是由另一個進程打開的,但它失敗並發生異常。

有關詳細信息,請參見FileShare枚舉。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM