StreamWriter问题(可能对于你来说很简单)

gwf25sz 2010-07-22 06:12:51
" image=╬image/a╬+imageList[i].value+╬.gif╬;\r\n"

解析后用StreamWriter写入文件后发现文件内变成:

image="image/"+imageList[i].value+".gif";

/后面的a没了!!!!

不仅如此,经过多次测试后 发现 / 后面放再多字母,写入文件后都会消失 -0-

比如

"/aaaaaaaaaaaafasjflsahfiusahfsaiof025"

会变成

"/025"


如何解决??????
...全文
85 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
gwf25sz 2010-07-23
  • 打赏
  • 举报
回复
重启电脑就好了·······缓存问题?
gwf25sz 2010-07-23
  • 打赏
  • 举报
回复
失望中。。。
无语的回答。。。

写入方法是公共的我用来写了几十个页面都没问题
既然有人要看,那我就贴出来,看看是否如你所说是代码问题:

/// <summary>
/// 文件写入
/// </summary>
/// <param name="UserID"></param>
/// <param name="fileName"></param>
/// <param name="htmlCode"></param>
private static void CreateFile(string UserID, string fileName, string htmlCode)
{
fileName += fileName.IndexOf(".html") != -1 ? "" : ".html";
string localPath = "E:/DotNet/Sun/SunDecorativeSystem/Users/" + UserID;
if (!Directory.Exists(localPath))
{
Directory.CreateDirectory(localPath);
}
localPath += "/" + fileName;
if (File.Exists(localPath))
{
File.Delete(localPath);
}


FileStream fs = new FileStream(localPath, FileMode.CreateNew);
StreamWriter sw = new StreamWriter(fs, Encoding.UTF8);
sw.AutoFlush = true;
htmlCode = htmlCode.Replace("╬", "\"");
sw.Write(htmlCode);
sw.Flush();
sw.Close();
fs.Close();
}

justfortemp 2010-07-22
  • 打赏
  • 举报
回复
  string path = filename;
try
{
if (isunicode)
{
using (StreamWriter sw = new StreamWriter(path, isAppend, Encoding.Unicode))
{
sw.WriteLine(line);
}
}
else
{
using (StreamWriter sw = new StreamWriter(path, isAppend))
{
sw.WriteLine(line);
}
}

return true;
}
justfortemp 2010-07-22
  • 打赏
  • 举报
回复
代码看看
viena 2010-07-22
  • 打赏
  • 举报
回复
或者你直接用FileStream来写
viena 2010-07-22
  • 打赏
  • 举报
回复
肯定是你写的方法不对咯
你不说怎么写的谁能猜得出来呢

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧