【发布时间】:2011-11-16 12:14:38
【问题描述】:
因为我使用的是非拉丁字母,所以如果我使用 StreamWriter,字符是不正确的。
String line;
StreamReader sr = new StreamReader(@"C:\Users\John\Desktop\result.html");
line = sr.ReadLine();
while (line != null)
{
line = sr.ReadLine();
if (line.Contains("</head>"))
{
line = "<img src=\"result_files\\image003.png\"/>" + line;
}
}
sr.Close();
这里我正在编辑要在文件中编辑的字符串,但我没有将它保存在同一个文件中。该怎么做?
【问题讨论】:
-
我认为在您的代码 sn-p 中您只是在堆中操作字符串,StreamReader 仅用于读取而不是用于写入,您要编写哪个非拉丁字母?是 > 标志吗?
-
可以在StreamWriter上设置编码
-
但我并不总是有这个文件。也许编码会有所不同。
-
从您上次的评论中不清楚问题出在哪里。读取文件或将其写回新文件时是否收到不正确的字符?您真的想要一个新文件还是只想修改现有文件?