在使用File.Create()之后,另一個(gè)進(jìn)程正在使用的文件我正在嘗試檢測(cè)一個(gè)文件在運(yùn)行時(shí)是否存在,如果沒(méi)有,創(chuàng)建它。然而,當(dāng)我試圖給它寫(xiě)信時(shí),我卻得到了這個(gè)錯(cuò)誤:進(jìn)程無(wú)法訪問(wèn)文件“myfile.ext”,因?yàn)槠渌M(jìn)程正在使用它。string filePath = string.Format(@"{0}\M{1}.dat", ConfigurationManager.AppSettings["DirectoryPath"], costCentre); if (!File.Exists(filePath)) {
File.Create(filePath); } using (StreamWriter sw = File.AppendText(filePath)) {
//write my text }有什么解決辦法嗎?
在使用File.Create()之后,另一個(gè)進(jìn)程正在使用的文件
ibeautiful
2019-07-20 14:39:22