【发布时间】:2016-04-13 04:31:21
【问题描述】:
如果指定位置存在,我正在检查文件是否存在,如果存在,我将用 ' 替换单引号。为此,我使用的是 WriteAllText 方法。据我所知,WriteAllText 将用于Create file and write the text and close it, target file is already exists, it will be overwritten。
我不知道为什么我在使用时收到System.IOException
var file = AppDomain.CurrentDomain.BaseDirectory + "test";
if (Directory.Exists(file))
{
string text = File.ReadAllText(file + "\\test.txt");
text = text.Replace("'", "'");
File.WriteAllText(file + "\\test.txt", text);
}
注意:我在 Application_BeginRequest 方法中使用这个。
建议我如何避免这个异常?
【问题讨论】:
-
只需交叉验证使用它的任何其他应用程序(如记事本等)..
-
当您收到
IOException时,它说的是InnerException?这应该让您知道出了什么问题。
标签: c# file writealltext