在使用File.Create()之后,另一个进程正在使用的文件我正在尝试检测一个文件在运行时是否存在,如果没有,创建它。然而,当我试图给它写信时,我却得到了这个错误:进程无法访问文件“myfile.ext”,因为其他进程正在使用它。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 }有什么解决办法吗?
                    
                    
                3 回答
                            摇曳的蔷薇
                            
                                
                            
                        
                        
                                                
                    TA贡献1793条经验 获得超6个赞
File.Create(FilePath).Close(); File.WriteAllText(FileText);
- 3 回答
 - 0 关注
 - 421 浏览
 
添加回答
举报
0/150
	提交
		取消
	